For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to: Create a Table In Microsoft Templates (DOCX, PPTX)

Build a DOCX related list table by placing a Word table between tableformat tags and mapping each column to a SOQL field.

Use this pattern when you need a repeating table in a DOCX template.

The SOQL logic stays the same.

The table wrapper changes.

What DOCX needs

A DOCX related list table needs three rows in Microsoft Word:

  1. A header row

  2. An odd row with placeholder text

  3. An even row with placeholder text

S-Docs uses the odd and even rows as the repeating pattern.

Basic pattern

docx-related-list-table.txt
[{{!<lineitemsSOQL>
<tableformat>]

| Product | Quantity | Total |
| sample   | sample   | sample |
| sample   | sample   | sample |

[</tableformat>
<soql>
  SELECT Product2.Name, Quantity, TotalPrice
  FROM OpportunityLineItem
  WHERE OpportunityId = '{{!Opportunity.Id}}'
  ORDER BY SortOrder
</soql>
<column>Product2.Name</column>
<column>Quantity</column>
<column format-number="#,##0.00" prefix="$">TotalPrice</column>
</lineitemsSOQL>}}]

Build it step by step

1

Create the table in Word

Insert a table with the number of columns you want to display.

Use the first row for visible headers.

Use the second and third rows as sample rows for styling.

2

Add the opening tags above the table

Place this block before the table:

This tells S-Docs to treat the Word table as the output format for the related list.

3

Add the closing tags and query below the table

Place this block after the table:

<soql> defines the rows.

Each <column> defines one output column.

4

Match columns to the query

Each <column> must match a field returned in SELECT.

Keep the column order aligned with the visible header order.

If you use relationship fields, use dot notation in both places.

Example for Opportunity Products

Use this pattern to show products from an Opportunity in a DOCX table.

Common fixes

  • Syntax prints as text: Use square brackets around the full block in DOCX.

  • No rows returned: Check the WHERE clause against the template base record.

  • Blank column: Add that field to SELECT and to a matching <column>.

  • Table does not repeat correctly: Make sure the Word table has header, odd, and even rows inside the tableformat block.

  • Wrong values in a column: Match the <column> name to the queried field or alias exactly.

Keep going

Last updated

Was this helpful?