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

Merge Fields With Microsoft Templates (DOCX, PPTX, XLSX)

Learn how to add merge fields to DOCX templates and use the square-bracket syntax required in Microsoft Word files.

Inserting Merge Fields in DOCX Templates

Merge fields pull live Salesforce data into a DOCX template.

They act as placeholders. At generation time, S-Docs replaces them with record values.

What a DOCX merge field looks like

Use this pattern:

[{{!Object.Field}}]

Examples:

[{{!Opportunity.Name}}]
[{{!Opportunity.Account.Name}}]
[{{!Contact.Email}}]

DOCX templates require square brackets around the merge field.

DOCX also uses inline formatting syntax inside the field.

How to add a merge field in a DOCX template

1

Choose the record value

Identify the object and field you want to merge.

Example: Opportunity.Name

2

Insert the merge field in Word

Place your cursor where the value should appear.

Then insert or type the DOCX merge field syntax:

[{{!Opportunity.Name}}]
3

Add formatting if needed

Formatting stays inside the merge field.

Example:

[{{!Opportunity.Amount #,###.##}}]
4

Upload and test

Upload the .docx file to the template.

Generate a document from a real record.

Confirm the value and formatting are correct.

Quick examples

Plain text field

Parent relationship field

Number formatting

Date formatting

Merge field inside a conditional block

Quick reference: common DOCX merge field patterns

This is a practical reference for the patterns you will use most.

Standard field output

Use square brackets around the field.

Number formatting

Apply the format inside the field.

Date formatting

Apply the date pattern inside the field.

Replace characters or values

Use replaceAll inside the field.

Use #comma# if a replacement value must contain a comma.

Named query output

Wrap the output field in square brackets.

Conditional output

Wrap both RENDER tags in square brackets.

Common issues

  • Merge field prints as text because the square brackets are missing

  • Field path is wrong or incomplete

  • replaceAll syntax is malformed

  • Query output field is not wrapped in square brackets

  • Word proofreading markup breaks generation

Last updated

Was this helpful?