Iterating through records

Writers, this needs to be reorganized and probably split up

Templates can iterate through a list of records related to the current record. To accomplish this, include a portion of the template between #LOOP_BEGIN and #LOOP_END tokens and that portion will be repeated for each record related to the current record.

Note: Having too many loops in templates and formulas may result in performance degradation, because Platform will retrieve many records from the database to compute the results. Use template loops with caution. In many cases Group Functions or the Query API are better alternatives.

For example, the following Template code renders a list of related items:

<ul>{!#LOOP_BEGIN.R8011504#8108944}
   <li>Item: {!R8011504.R8011504} Amount: {!R8011504.amount}</li>
   {!#LOOP_END.R8011504}
</ul>
   

To create a template loop using the Template Editor:

  1. In the left dropdown, select the object type related to the current record.
  2. Select and copy the #LOOP_BEGIN token.

    If you have several views for a related record, you will have a choice of the view to use for iteration that allows an easy way to filter and sort related records in templates.

  3. Create a portion of the template to be repeated for each related record.
  4. Select and copy the #LOOP_END token.

Note: The #LOOP_BEGIN token uses original ids of views that will be preserved when your template is published as a part of an application and installed in another tenant.

Platform does not support nested loops (loops within a loop). If you need nested loops consider using an API instead. For example, to use template tokens from parent record while looping through related record use object integration name (of parent record) as prefix, try the following:

<ul>
    {!#LOOP_BEGIN.R8011504#8108944}
    <li>Bill: {!order.name} Amount: {!R8011504.amount}</li>
    {!#LOOP_END.R8011504}
</ul>