Replace Tokens in Word Document
Audience:
Low-code EngineersSkill 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.
Related Actions
| Action Name | Description |
|---|---|
| Convert from HTML to Word | Creates a Word document from HTML, optionally based on a template. |
| Generate PDF | Creates a PDF from an HTML template. |
| Send Email | Sends 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:
- Show the Developer tab: File > Options > Customize Ribbon, then check Developer.
- Place the cursor where the value should appear.
- On the Developer tab, select Plain Text Content Control (or Rich Text Content Control).
- With the control selected, select Properties.
- In Title, enter the token, for example
[FirstName], and select OK. - 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.
- Save the template as a
.docxfile 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
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| File Identifier | The 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. | Yes | empty string | Yes |
| Folder | The 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. | Yes | none selected | Yes |
| Pattern | The name for the new document, without the extension, for example Contract-[User:Username]. .docx is always added. Leave empty to use a random name. | Yes | empty string | No |
| Handle Duplicates | What 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. | No | Rename | No |
Output Parameters Reference
| Parameter | Description |
|---|---|
| Output Token Name | Optional. 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.docfiles and Word templates (.dotx) aren't supported. Save the template as a.docxdocument. - Folder IDs. Use a folder path in
Folderrather 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
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