Document Generation
...
Template - Actions
Word DocX Template Actions

Insert Loop

The Insert Loop action allows you to repeat a specific section of a template with fields dynamically populated from object records. This repeated section is added consecutively in the template, with each iteration using field values from the next record in a collection. The records used for the loop can be retrieved from any Record Collection in Salesforce.

How to Insert a Loop-

Step 1- Prepare a Record Collection Resource

To insert a loop, first create a Record Collection Resource that defines the collection of records over which the loop will be performed. Example: If your base object is Account and you want to loop through related Opportunities , create a Record Collection Resource that retrieves all Opportunities where:

  1. Account Id = Record.Id (i.e., the current Account record's Id).
Document image


Step 2- Insert the Loop in the Template

  1. Use the Select Action dropdown and choose Insert Loop .
  2. In the Resource Type dropdown, select the Record Collection Resource you just created.
Document image


Step 3- Customize the Loop Content

  1. The inserted loop will appear in the template with a placeholder section labeled "Click or tap here to enter text.

    Document image
    
  2. Click the placeholder to select it, erase the placeholder text, and begin creating the content for the loop using fields from the selected Record Collection. Use the Insert Field action to add fields dynamically within the loop.

Example:

In the image below, the loop iterates over related Opportunities. Inside the loop, two fields — Name and Opportunity Id — have been inserted as dynamic text.

Document image


Preview the Generated Document

When the document is generated, the loop content will repeat for each record in the collection. Each iteration will populate the fields with data from a single record in the collection. Example Output: For an Account with two related Opportunities, the content inside the loop will repeat twice, once for each Opportunity. Generated Document Sample:

Document image


Go to 4:36 to see the Insert Field action being used to create a sample receipt in Microsoft Word.