OL Learn

Datamapper repeat in repeat with action

I would like to use an Action Step under a Repeat Step under a Repeat Step. This is because the
standard Extraction Step is not sufficient. So I have created a data model with the needed tables and fields:

Polis (table)
Clausule (table)

However I cannot reach Clausule to do an addRow() as it is “stuck” on the Data Model root level … I only see Polis.

In the Extraction Step there is the Data Table in Extraction Definition, in this case it would be filled with record.Polis.Clausule … which will indeed fill the fields :wink:

How can I achieve this in my JavaScript?

Hi @sybren.kuperus,

First of all, welcome to the forum!

Can you let us know please why you would like to extract FieldX and FieldY by a Action Step and not by a Extraction Step?

How can I achieve this in my JavaScript?

You can achieve this by assigning the value of the steps.currentLoopCounter property in the first Repeat Step to a variable by making use of an Action Step. For this you can make use of the following Action Step script, for example:

var firstLoopCounter = steps.currentLoopCounter;

Make sure that you’re executing this Action Step before the second Repeat Step.

I wasn’t able to fully test it but I suppose that you could use the following JavaScript code in the Action Step which has been added to your second Repeat Step:

if (typeof firstLoopCounter !== "undefined") {
    var fieldX = data.extract('./field-x');
    var fieldY = data.extract('./field-y');
    if (fieldX !== null || fieldY !== null) {
        var secondLoopCounter = steps.currentLoopCounter;
        if (record.tables.Polis.length < firstLoopCounter) {
        var row = record.tables.Polis[firstLoopCounter - 1].tables.Clausule.addRow({});
        if (fieldX !== null) {
            record.tables.Polis[firstLoopCounter - 1].tables.Clausule[row].set({FieldX: fieldX});
        if (fieldY !== null) {
            record.tables.Polis[firstLoopCounter - 1].tables.Clausule[row].set({FieldY: fieldY});
} else {
    throw "The variable \"firstLoopCounter\" is undefined.";

Thx for the info, I’ll give this a try! I need to use an Action Step because one of the fields in Clausule needs to be split into separate lines, creating an array under Clausule. This needs to be in current Polis, current Clausule.