How to read external csv and write it to a record field

Hi,

I want to read an external (local) csv file and write the data to a record field.
I have added a record field called “colorTable” in an extraction step and tried to store the data directly in that record field (preprocessor script) but get an error.
So I added an automation variable in the preprocessor and try to store the data in it and in the extraction step read the data from the automation variable into my record field, but the record field remains empty.

Content of the csv file (I don’t have a header line):

FreshGreen;#00FF00;#04B404
CoolBlue;#58FAF4;#00BFFF
FunkyPink;#FF00FF;#FE2EC8

My script within the Datamapper Preprocessor:

var line;
var colorTable = “”;

var csv = openTextReader(“C:\out\colorTable.csv”);

while( (line = csv.readLine()) != null ){
line = line + “$$”;
colorTable += line;
}

csv.close();

automation.variables.colorTable = colorTable;
//record.fields.colorTable = colorTable;

Expected result in the record field colorTable:

FreshGreen;#00FF00;#04B404$$CoolBlue;#58FAF4;#00BFFF$$FunkyPink;#FF00FF;#FE2EC8

I need the content of the csv as a lookup table within a Designer script. The input data (xml) holds only the color name (e.g. FreshGreen) and I have to replace it with one of the matching hex color values in my script.

Any help would be great.

Regards,
Thomas

I don’t think that’s working because in the preprocessor the record field isn’t available.

But you could add the colortable string to a preprocessor property and after the preprocessor assign the property to the custom record field in an Action step.