Extract some column to detail record

Hi,

Ya have a txt file like that :

NAME COLOR1 COLOR2 COLOR3 COLOR4
Mike blue red
Denis red green blue
Roger white

I want to have a construction something like that in my datamaper

Record [1]

   +--- Name : Mike

   Colors[1]

         +--- Color : Blue 

   Colors[2]

         +--- Color : Red

How could I split my columns in a detail array name Colors ?

Thanx.

Not sure I understand. Are you trying to create a detail table of Colors per record? Meaning you need to iterate on the same line? Ok Proceed as follow:

Add an Action step to extract the array of colors with the expression

var arrColors = data.extract(10,65,0,1,“<br />”).trim().split(" ");

Add a Repeat step:

  • set repeat type to “Until statement is true”
  • Maximum iterations on each line to : parseInt(arrColors.length);
  • Condision based on JavaScript with expression: parseInt(steps.currentLoopCounter);
  • Operator: is equal to
  • Right hand operator based on JavaScript with expression: parseInt(arrColors.length);

Inside the Repeat Step, insert a Condition step

  • Based on JavaScript with the expression: parseInt(steps.currentLoopCounter);
  • Operator: is equal to
  • Based on Value
  • Value: 0

In the True branch of the above condition, Add an Extract step:

  • set the Mode to JavaScript with the expression: arrColors[parseInt(steps.currentLoopCounter)-1];

In the False branch of the condition:

  • Add a GoTo step with Target type: Line; from Current position and Move by -1
  • Add an Extract step and set the Mode to JavaScript with the expression: arrColors[parseInt(steps.currentLoopCounter)-1];

After the Condition but still within the Reapeat loop, make sure your Go to step Moves by 1 (line)

I obviously don’t know what your end goal is, here, but it may be simpler to just extract the entire line and convert it to a JSON string that you store in a field in your record.

Then whenever you want to use it in the template, you simply iterate through the JSON string. You’d just use a Javascript Extraction step with something like this:

var jsonColors = ;
var aColors = data.extract(12,81,0,1).split(" ");
for(var i = 0; i < aColors.length; i++){
if(aColors[i]){
//logger.info(aColors[i]);
jsonColors.push(aColors[i]);
}
}
//logger.info(JSON.stringify(jsonColors));
JSON.stringify(jsonColors);

This gets you nice little strings like [“red”,“green”,“blue”]

hi, we have complex templates developed using csv and xml data. our sister company is also providing the same data in text format. spent weeks trying to figure out how to create a detail table out of array of fields. this exemple has saved me the trouble of redevelopping my templates using text data to match the csv and xml data models already in place. i think a new feature allowing the goto step to move left or right might also be beneficial. perfect.thanks