Please enable JavaScript to view this site.

InterFormNG2 Manual

You can make InterFormNG2 repeat a selection of elements in a sub-folder. The repeat element repeats e.g. the elements a number of times, where this number can be either fixed or found via an Xpath expression, but it can also repeat the sub-folder for each input node or page in the input file.

 

To insert a repeat element you click this element in the top of the designer:

 

NG2Repeat0001

 

The icon is found by clicking the '+' icon to reveal the second row of design elements:

NG2Repeat0002

 

You see the properties of the repeat element, when you insert a new or double click on an existing one in the element tree.

 

The number of repeats can be set in these manners:

 

1.A numeric value as a constant or an Xpath expression e.g. a value from the input XML file and/or with a variable. The numeric value defines how many times the design elements inside of the repeat sub-tree is to be repeated.

2.The repeat can execute all elements in the sub-tree for each node in an input XML file.

3.A sub-tree of elements can be repeated for each page in an input spooled file on the IBM i platform.

4.A tip: If you want to avoid a warning in the job logs, then you can consider this: Avoid warnings for repeats, that selects no nodes.

5.You can also setup a repeat to iterate over input and pages and input lines in a spooled file. An example of this is included in the section, How to iterate across detail lines in spooled file.

 

 

Numeric value for the repeat

This section covers the situation, where you want to repeat a sub-tree of elements a number of times. The number can be either fixed or dynamic.

 

Constant as repeat

 

NG2Repeat0003

 

You can use a constant as the number to repeat if you e.g. wants to insert multiple identical elements below (or beside) each other in the flow:

NG2Repeat0004

Above we insert 5 identical containers/boxes.

 

You can also use a variable with the repeat to insert a range of numbers e.g. 1 to 10:

 

NG2Repeat0005

 

 

Numeric repeat with XPath expression

The number of repetitions can also be set as a variable/XPath, but then you should remember to convert the value to a number:

 

NG2Repeat0006

 

In the example above we take the value of the DocumentNo node from the first Document node in the input XML file, convert it into a number and use it for our repeat.

 

Warning:Template.001014: Invalid element. Repeat expresssion evaluated to 0 nodes

If the repeat selects a node set that is null (no nodes match), then you will see a warning like below in the job log:

NG2RepeatWarning0001

 

Above the node selection in the template is shown. If you want to avoid this warning, then you can insert the repeat loop inside an if element like below:

 

NG2RepeatWarning0002

 

With the expression boolean(<path>) we can verify if there is at least one node in the selected node set. Instead of boolean(<path>) you can also use the condition:

count(/Root/DocumentX)>0.

 

 

Repeat for each node in input XML file

If you e.g. want to print out all detail lines of an input XML file in the designer, then you should use the repeat design element to iterate across all detail lines of the input file.

One example is shown here.

If you have loaded the demo XML file, then you can e.g. print out all detail lines in this manner:

 

Add a Repeat element in the designer and click the magnifying glass on the right:

 

NG2Repeat0007

 

Now you can search for 'line' and click the 'Sales_Invoice_Line' node in the xml file:

 

NG2Repeat0008

 

- and the xml path of the node is inserted into the Repeat element:

 

NG2Repeat0009

 

Inside the Repeat element (e.g. in a text element), you can now refer to the relative path from the detail line node to select data from the current detail line, if you refer to the relative path like so:

 

NG2Repeat0010

 

Please notice, that you need to refer to the relative path (strip the start of the path from the path setup in the Repeat element). That mean e.g. in the example above, that the path inserted in the text element would be as below if you referred to the node outside a repeat:

 

/IF_Type/Sales_Invoice/Sales_Invoice_Header/Sales_Invoice_Line/Line_Type

 

But you need manually to remove the path specified in the Repeat to reduce this to ./Line_Type.

 

If you want to create aligned columns of the detail lines, then you can e.g. use a container, where the flow direction is row and set fixed widths for each text element of the detail lines:

 

NG2ForEach0007

 

With fixed widths you can create this list with the demo sample XML file:

 

NG2ForEach0008

 

This lists all detail lines of all the documents.