Contact us Blog

Combining list fields with commas in Word documents

In some situations, you might need to generate a list of field values separated by commas in a Word document. For example, you might be creating a simple summary document for each household, with the household name at the top, and the names of the children in the household separated by commas, as in the screenshot below. The key issue here how to create the list of first names. The household name comes from the Account object, and can easily mapped to a single field in that object. But the list of children comes from the related list of Contact records. The need is to put together a comma-separated list of the first names of the contacts, with the last pair of first names separated by "and".

Solution

To make this happen, you will need to use the combine function.
  1. Create a template field with five parts, separated by colons: the Record group name, the name of the sublist field whose values should be combined, the word combine, the default separator (comma in the above example), and the last separator (the word "and" in the above example). Below is a screenshot of the template. The parts of the combine field are as indicated below.
  2. When building the merge action, map the fields to the sublist as indicated in the sublists documentation. Note that you don't have to create a TableStart/TableEnd pair for the sublist. The existence of the "combine" function tells the generator that you need a sublist, with a record group named Members (in this example). So it shows the record group panel, as in the screenshot below.

Examples and usage notes

Merge field Examples of output Comments
«Members:First name:combine: and » Abraham and Jessica and Maria Since no last separator is specified, the separator value and is used between all the parts.
«Members:First name:combine:-» Abraham-Jessica-Maria The separator used is a minus sign.
Some notes to bear in mind:

The Document Generator includes a means for producing sublists. But that is not adequate in the present situation, for two reasons. One, that the sublist mechanism requires the sublist records (the first names, in this case) to appear in a table, a bullet-list, a numbered list, or other similar block. And second, that mechanism doesn't offer a way to selectively include separators between the data - the separators in this case being the comma and the word "and".

To address this situation, the Document Generator provides a combine function that can be applied to a single field from a sublist, to produce text with embedded separators.