OL Learn

Add false rows in table

good morning people
I have a table that I need that always have 7 records, but there are situations that in the xml it comes less, my idea is to fill those rows with its columns with empty data, can I do it from the datamaper?

image

thank you very much!

In your preprocessor step, create a padding record-scoped property of type Integer.

Then, immediately after your Repeat loop that currently extracts all your detail items, add an Action step that runs the following JavaScript code:

sourceRecord.properties.padding = 7-record.tables.detail.length;

The padding property now contains the number of missing detail lines to create. Note that in this example, the detail table is named detail. Change that name to match your detail table’s actual name.

Now add another Repeat step, with the following parameters:

This loop will iterate as many times as needed to fill your detail table up to 7 items. If there are already 7 items in the table, it will simply be skipped.

Inside the loop, add an extraction step that extracts an empty value into one of your detail table’s fields (in this example, the field Number):

And finally, immediately after that extract step, add a Goto step that points to the top of the record.

Note of interest: starting with the upcoming 2021.1 release, all of the above can be replaced with a very simple script:

for(var i=record.tables.detail.length;i<20;i++){
	record.tables.detail.addRow({"Number":""});
};

That should make your life much easier. :slight_smile:

Thank you very much Phil, it works perfect, the only thing I add, that if there are more tables take the repeater to the end of the steps.
on the other hand I have version 2021.1 and the addRows method is still not included, or at least it gave me an error.

2021.1 has not been released yet… So you must have meant to say you have 2020.1.

That’s interesting, because I can download it and the release notes are accessible :smiley:
—> PlanetPress Connect 2021.1 - Offline Installer 4/21/2021


Best regards
-i.

Ahhh… you must have access to the partner preview release, then.
Still, the addRow() method should be available in that version. That’s how I created and tested my earlier script.

See https://help.objectiflune.com/en/pres-connect-user-guide/2021.1/#datamapper/API/Method_table_addRow.htm