I want to use the data mapper to total up line item data and then have the result as a record field.
I’ve set a property at the start and can create the record using that property at the end of the loop.
I’m using an action within a repeat loop (after each extraction) to increment the value of the property by a constant and it works perfectly; however, I want this constant to replaced by the extracted values from the previous step.
I don’t know how to read record values within the datamapper…
In your action task, set the Type for the action to Set Property. In the settings for the action, select your property in the dropdown list. Set its Based On value to Javascript. In the Expression field, add code similar to this:
You can read both data in your source record, or the record fields after they’ve been created, using the DataMapper API. Unfortunately I don’t currently have the documentation on that API (but it will be put online as soon as we can), but here’s a few pointers:
You can see the syntax of any data extraction (Extract Step) by first doing an extraction the standard way, and then changing the “Based on” property in the Extract Step to “JavaScript”. This depends on the data type, for XML it looks something like data.extract('./nodename'); , for text it’s something like data.extract(1,6,0,1,"<br />");
Extracting records is the same syntax in DataMapper as it is in Designer. You can use record.fields.fieldname for record fields or record.tables["tablename"][i].fields.fieldname; for a field in a detail table iteration (where “i” is the table entry index).
Data properties are access through data.properties.propertyname; , while Source Record properties are access by sourceRecord.properties.propertyname;
By the way when you’re in a JavaScript-enabled box, the auto completion helper will assist you in the right syntax, for example if you type record. , you’ll get a list of properties the record object has (like fields and tables).
Hint of the day: CTRL+SPACE while on an empty line shows the whole available objects and methods in the API!
I don’t get an error, but my numbers don’t add up correctly.
It might be worth point out that I’m creating 5 detail tables Lease, Payment, Service, Tyres and All - they contain only those values where the Type = the matching value.
It makes sense that the LoopCounter should work, but it seems to generate an error.
One more thing, it seems the value of steps.currentLoopCounter = number of repeats - not the current line index within the repeat (in my case = 9)
OK, so I think because I need to increment the property value, I need to use JavaScript instead of SetProperty. Plus I think I’ll try to create my own counter.
The LoopCounter variable won’t work in this case because it refers to the current iteration of the loop. Since you are not creating a new record in each of the detail tables you’re populating inside that single loop, the iteration counter will eventually become higher than the last record that was actually stored in any of the detail tables.
In that case, you can either create your own individual counters for each detail table, incrementing the proper one each time you add a record to the corresponding table, or you can use Evelyne’s comments (below) to directly re-extract the same value you just extracted and add it to your Property.