Repeat element

Repeat element

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.

    • Related Articles

    • Excel repeat

      You can insert a repeat element in the excel designer. The Excel repeat element works exactly like the repeat-element of the normal template designer. You can insert the repeat element in two ways: 1.You can click the repeat-element on the top to ...
    • Workflow variable element

      You can define two kinds of variables in your templates: 1.A normal variable, which is defined and used only within the template. 2.A workflow variable, which can be used for e.g. for sending user defined variable information from the workflow to a ...
    • Line element

      If you want to insert a line in a template, then you need to click the line element icon: After you have clicked the line element, the pointer icon changes to a cross hair icon indicating, that InterFormNG2 now expects you to start and end position ...
    • Table element

      You can use a table element to insert design elements in organized rows and columns. Each cell in the table can be surrounded by a border and/or filled out with a color. You can even create a dynamic table with a row for each detail line in the input ...
    • Text element

      If you want to insert any kind of text in InterFormNG2, then you should use the text element. You can insert a new text element if you click on this icon: The data, that you can output as text are these types: 1.A text constant. 2.Drag nodes from an ...