Counting rows in a Repeat Section in a Template ‘_Count’

You often need to know how many rows have been entered into a Repeat Section.

For example, you may want to use a singular expression if only one row has been entered (e.g. ‘Trustee’), but a plural expression if more than one row has been entered (e.g. ‘Trustees’).

Another example is where you want to insert the content of a repeat section in a document, but if no rows have been entered (i.e. the table is empty), then you may want to include a message (like “Not applicable”).

ZumeForms has a built-in system function to access the total number of rows in a repeat section from within your document templates. You do this by adding the extension “_Count” to the end of the Repeat Section:

{MERGEFIELD SectionName_rpt_Count}

So if the repeat section called SectionName_rpt had 3 rows, then the above mergefield would result in “3” being inserted into the document template.

You can also use the result of the _Count function in calculations in your document templates:

{ IF {MERGEFIELD SectionName_rpt_Count} > 1 "Plural" "Single"}

This will insert “Plural” into your document if there is more than one row, or “Single” if there is only one row.

If there are no rows in the repeat section, i.e. _Count = 0, then the result of {MERGFIELD SectionName_rpt_Count } will be “”, i.e. null, and NOT “0”.

So if you want to test for the _Count of a repeat section being none (i.e. 0), you would use the following expression:

{ IF "{MERGEFIELD SectionName_rpt_Count}" = "" "No rows entered" "There is at least one row"}

On the other hand, if you want to insert the current row number into the document created from the Template, then you can use the built-in system Field ‘rpt_Index‘. For an explanation of how to do this, click here.