Adding an iteration element

Rather than copying and pasting blocks of your template to duplicate the sections, use the do while condition property in the Iteration element to create loops in your template.
Restriction: New feature icon The iteration element is available only in version 2 templates.

Before you begin

About this task

Iterations® work with queries applied to them or to their child elements in two stages. First, during document generation, these elements are processed one time. Second, the conditions that are applied to the Iteration element are processed. If the conditions are true, then the Iteration element and its child elements are processed again. The sections continue to be processed until the condition is no longer true.

In the first stage, the data that is used in the condition must change so that there is a finite number of steps. This condition is what makes the processing of the sections end and not continue to loop. In step 5 of the example below, the condition is that the teamList variable is not empty. So the condition is true so long as there are data entries for the teamList variable. When there are no more data entries, the condition is false and the repetition ends.

To have the queries executed multiple times, add a dynamic Data Source Configuration element inside the loop container to force the queries to be initialized more than one time.

Procedure

  1. In the Palette view, select an Iteration icon Iteration element and drag it into the template content editor.
    Note: You cannot put Iteration elements into master pages.
  2. Select the section of the template to duplicate and drag it into an Iteration element.
  3. Select the Iteration element.
  4. In the Properties view, select the Specific tab.
  5. In the do while condition value, click the Configuration icon.
  6. Select the Script expression tab. You cannot enter the script in the Simple value tab because it creates an infinite loop.
  7. Select a variable. Creating a loop with a variable ensures that the loop is applied a specific number of times, or as many data values are applied by using this variable.
  8. Enter the script.
  9. Click OK.
  10. Save the changes.

Example

Creating a list of team members to be used:
  1. Create an external variable named teamList.
  2. Create an external variable named currentMember.
  3. Create a table element and apply a condition:
    1. Add a Table icon Table element to the template content editor.
    2. Enter 1 column and 2 rows.
    3. Right-click the Table element and select Data > Edit condition.
    4. Select the teamList variable.
    5. For the Left operand, select the teamList variable.
    6. For the Operator, select Not equal to.
    7. For the Right operand, do not enter a value.
    8. Click Add. The script result is: teamList != ""
    9. Click OK.
  4. In the first cell, add a heading for column:
    1. Add a Text icon Text element to the cell.
    2. Double-click the Text element to open the content editor.
    3. Enter a heading name as Team Member List.
    4. Click OK.
    5. In the Properties view, select the Font tab.
    6. Click Bold property.
    7. Select True and click OK.
  5. Add the Iteration element:
    1. Drag the Iteration icon Iteration element from the Palette view and place it between the rows of the table.
    2. Select the Iteration element.
    3. In the Properties view, enter this script for the do while condition property: teamList != ""
    4. Add two Container icon Container elements in the Iteration element. The first Container is used to calculate the first name from the list to be used in the current row. The second Container is used to end the loop so it does not continue unnecessarily.
    5. Drag the second row and its contents into the Iteration element and place it after the container elements.
  6. Assign a variable to the first container element:
    1. Right-click the first Container element.
    2. Select Data > Edit assignments
    3. Click Add.
    4. Select the currentMember variable and click OK.
    5. Select the Script Expression tab.
    6. Select the teamList variable and enter the script:
      var pos = teamList.indexOf( ",");
      
      if ( pos >=0)
      {
         // get the first member ( till the first comma)
          teamList.substr( 0, pos);
      }
      else
      {
          // last member
          teamList;
      }
    7. Click OK and OK.
  7. Assign a variable to the second container element:
    1. Right-click the second Container element.
    2. Select Data > Edit assignments
    3. Click Add.
    4. Select the teamList variable and click OK.
    5. Select the Script Expression tab.
    6. Select the teamList variable and enter the script:
      var pos = teamList.indexOf( ",");
      
      if ( pos >=0 && pos < teamList.length)
      {
         // get the first author ( till the first comma)
          teamList.substr( pos + 1);
      }
      else
      {
          // last member, remove it
          ""
      }
  8. Drag the currentMember variable from the Outline view to the cell in the second row.
  9. Test the output.

Feedback