Skip to main content
Version: 1.28 (Current)

Replace Tokens in Word Document

Audience: Low-code Engineers

Skill Prerequisites: Tokens, Microsoft Word content controls

Creates a new Word document (.docx) from a Word template by replacing tokens with their values. The template isn't changed. The new document is saved in the folder you choose, and its file ID is saved in a token.

Tokens are placed in the template using Word content controls, not typed as plain text. See Preparing the template before using this action.

Typical Use Cases​

  • Generate contracts, offer letters or certificates from a form submission
  • Fill in a company-branded template with customer or order details
  • Produce documents that users can still edit in Word afterwards

Don't use it to​

  • Build a document from HTML. Use Convert from HTML to Word instead.
  • Create a PDF. Use Generate PDF instead.
  • Repeat rows for a list of items, such as order lines. Each content control is replaced by a single value.
Action NameDescription
Convert from HTML to WordCreates a Word document from HTML, optionally based on a template.
Generate PDFCreates a PDF from an HTML template.
Send EmailSends the generated document as an attachment.

Preparing the template​

The action looks for content controls whose Title contains a token. It replaces the content of each of those controls with the Title's value after tokens are applied. Text such as [FirstName] typed directly into the document is not replaced.

To add a token to a template in Microsoft Word:

  1. Show the Developer tab: File > Options > Customize Ribbon, then check Developer.
  2. Place the cursor where the value should appear.
  3. On the Developer tab, select Plain Text Content Control (or Rich Text Content Control).
  4. With the control selected, select Properties.
  5. In Title, enter the token, for example [FirstName], and select OK.
  6. Format the control's placeholder text the way you want the value to look, for example bold or a particular font. The value takes the formatting of the first piece of text in the control.
  7. Save the template as a .docx file and upload it to the site.

The whole Title is tokenized, so it can mix text and tokens. For example, a Title of Dear [FirstName] [LastName], produces Dear Jane Doe,. Content controls whose Title doesn't contain [ or ] are left as they are.

Content controls are supported in the document body, including inside table cells, and in headers and footers.

Input Parameter Reference​

ParameterDescriptionSupports TokensDefaultRequired
File IdentifierThe template document, as a file ID or a path relative to the portal root. For example, if the file is Portals/0/Templates/Contract.docx, enter Templates/Contract.docx. The file must have the .docx extension.Yesempty stringYes
FolderThe folder to save the new document in. Select a folder, or in expression mode enter a folder path relative to the portal root. The folder is created if it doesn't exist. If empty, the document is saved in the Temp folder.Yesnone selectedYes
PatternThe name for the new document, without the extension, for example Contract-[User:Username]. .docx is always added. Leave empty to use a random name.Yesempty stringNo
Handle DuplicatesWhat happens if a file with the same name already exists in the folder. Rename saves the new document with a unique suffix added to its name. Overwrite replaces the existing file.NoRenameNo

Output Parameters Reference​

ParameterDescription
Output Token NameOptional. The name of the token that receives the new document's file ID, for example ContractFileId.

Considerations​

  • Content controls need some content. Leave the placeholder text in each control. A control with no content at all makes the action fail.
  • Values are plain text. HTML in a token value appears as text, and line breaks aren't kept.
  • Controls that wrap whole table cells or rows aren't supported. Put the content control inside the cell instead.
  • Only .docx. Older .doc files and Word templates (.dotx) aren't supported. Save the template as a .docx document.
  • Folder IDs. Use a folder path in Folder rather than a folder ID.
  • If anything goes wrong, users see a generic error message. The full details are written to the site's event log.

Examples​

tip

To understand how to use the below examples, please see Running Examples.

1. Generate a contract and email it​

The first action fills in Templates/Contract.docx and saves the result as Contracts/Contract-<ContractNumber>.docx, replacing any existing file with that name. The file ID is saved in the ContractFileId token, which you can use to attach the document in a following Send Email action.

{
"Title": "Replace Tokens in Word Document",
"ActionType": "ReplaceTokensWord",
"Description": "Fill in the contract template",
"Condition": null,
"Parameters": {
"FileIdentifier": "Templates/Contract.docx",
"Folder": {
"Expression": "Contracts",
"Value": "",
"IsExpression": true,
"Parameters": {}
},
"Pattern": "Contract-[ContractNumber]",
"Duplicates": {
"Expression": "",
"Value": "Overwrite",
"IsExpression": false,
"Parameters": {}
},
"OutputTokenName": "ContractFileId"
}
}

Revised 09/25/2026