Datamapper Text file extraction

Hello,

I have a text file which looks like this.

JOB_DocumentType INKORD
JOB_DocumentNaam EA_721149_2011-05-18-15.34.31.866000
JOB_User NICK
JOB_Language HOL
JOB_UID C7BBA0038D6419468B740004AC11883A

So I want a field JOB_DocumentType with the value INKORD or field JOB_User with the value NICK. It can be that sometimes fields will not be in the text file.

How can I achive this?

Regards,

Nick

Hello Nick,

This is a little trickier than our usual files and does require a bit of scripting to get right. The reason is that you can’t programmatically create fields in your data model. So this is still possible, however it requires some Javascript actions.

Instead of attempting to explain the whole thing, here’s a file that does what you need, using the exact text that you have above. If this is part of a bigger job though, it might require some tweaking…

The basics:

  • All 5 fields are created in the data model (right-click on “record”, then “Create Field”)
  • They are given a default value (right-click, “Default Value”) that’s just a space (this seems to be an issue, you shouldn’t need the default value, I’ll report it).
  • A “Repeat” step is created which goes through all the lines (this is what you’d change if your data file has other stuff)
  • An “Action” step uses a script to grab the line, split it into two values (using the space inbetween, that’s split(" "); in the end of the first line), then it sets the value of the field refered on the left part, with the value on the right part.

Hope this helps!

~Evie

The easiest way would probably be to start with a GOTO step that looks for the first intance of JOB_. Then you add a while loop that iterates on each line until the first 4 characters of each line are no long JOB_:

Then, inside the loop, you use nested conditions that determine which field to extract, based on the next few characters following JOB_. Inside the conditions, in the True branch, you add an extraction step for the proper field and you set the extraction to an arbtrary length (e.g. 50) and extract everything after the keyword JOB_xxxx. In the following example, I used a POST function to do that:

Obviously, your data model still needs to have all fields defined and you should set a default value for them so that you will know whether or not the fields were present and extracted when you run the process.

Great, only 1 question, left within the repeater I have created a condiional because JOB_User can exists twice so:

JOB_User Nick
JOB_User Henk

Condition is if value = Fieldname = JOB_User true, than i want to the field an and value to table.

var currentLine = data.extract(1,88,0,1,“”).split(" ");
var fieldname = currentLine[0];
var fieldvalue = currentLine[1];

i++;
if(fieldname.length > 0) {
logger.info(fieldname + “,” + fieldvalue);
//record.fields[fieldname] = fieldvalue;
record.tables[“highlight”][i].fields[fieldname] = fieldvalue;
}

But it throws an error Cannot read property 0.0

Any idea?

Regards,

Nick