- 03 Nov 2021
- 3 Minutes to read
- Print
- DarkLight
Replace Text in a Word Document
- Updated on 03 Nov 2021
- 3 Minutes to read
- Print
- DarkLight
Overview
The following document demonstrates how to use Replace Text in Word Document step from the Data > Documents category in the Steps tab. This step gets Bookmarks from a Word Document, replaces them with desired text input, then in turn returns an updated Document File.
This step bears similarity in functionality to the Replace Bookmark with Text (Dynamic) step in that both steps can be used to locate Bookmarks and replace them with the desired text value. However, this step requires multiple duplicate instances within a Flow to replace text within a Word Document.
Failure to use a Word-generated document will result in unexpected results and failure to apply the specified changes.
Example
The following example demonstrates how to use the Replace Text in Word Document step as well as how to properly configure both the Token and Bookmark Replace Modes.
For more information on how to import a file into Decisions, see Importing and Exporting Projects.
- Project File:
- Example Document containing Bookmarks:
- Example Document using Tokens:
To Replace Text in a Word Document via Flow:
Text Replace Form Flow
- From a Designer Folder in the Decisions Studio, select the CREATE FLOW button, then CREATE a new Flow.
- From the Flow Designer, attach a Show Form step from the Favorite Steps category to the Start step.
- From the Properties of the Show Form step, select Pick or Create Form. Then, CREATE a new Form. Additional InformationThis Form will be used to define Input for the Bookmarks that will be added to the document.
From the Form Designer, design a Form containing four Text Box components, four corresponding Labels (Name, Company, Address, Number), and a single Button (labeled "Submit"). Save the Form, then Close out of the Form Designer.
Back in the Flow Designer, from the Properties of the Form step, set each Input to Ignore.
Under Steps > Data > Documents, attach a Replace Text in Word Document step.
From the Properties of the Replace Text in Word Document step, select the desired Replace Mode.
Save the Flow, then proceed to the Debug section below.
Replace Mode: Bookmark
The following discusses how to configure a Replace Text In Word Document step via the Bookmark Replace Mode:
- With the Replace Text in Word Document step selected, from the Properties panel, under Configuration, either drag and drop the desired Word Document into the Drag file here field, or select it via the CHOOSE FILE button.
- Under Inputs, set _GoBack to Ignore, then Select From Flow map each Output from the Form to its respective Input (Address to FullAddress, Company to Company, etc...).
- Attach the Failed path to the End step, then connect another Show Form step to the Done path. From the Properties of the Show Form step, select Pick or Create Form then CREATE a new Form.
- From the Form Designer, create a Form containing a single File Download component and one Button (labeled "Done") from the Favorite Components section of the Form Controls tab. Save and Close the Form Designer.
- Back in the Flow Designer, connect the Done path to the End step. Then from the Properties of the File Download Form, map OutputDocumentFile to Download File.
Replace Mode: Token
To configure the Replace Text in Word Document step using Tokens instead of Bookmarks:
- From the Properties of the Replace Text In Word Document step upload the desired document via the Pick Document File Input.
- Under Replace Tokens define the Start Of and End Of Token respectively (in this case square brackets [ ]).About TokensUpon defining the Start Of and End OfToken values, the step will populate with the matching Inputs reflected by the Tokens containing that lead and end with those values.
Under Inputs, Select From Flow each Output from the Replace Text Form to its corresponding value on the Replace Text In Word Document step.
Save the Flow, then proceed to the Debug section below.
Debug
- From the Flow Designer, select the Debug link from the top Action Bar.
- Upon reaching the first Form, provide the desired values for the Replace Text In Word Document step, then click Submit.
- Once the Flow reaches the Download Form, select Download File.
- Open the downloaded file and verify that the Tokens or Bookmarks have been replaced with the input values.