Conditional text in Microsoft Word

How to use conditional text in Word.

If you do not like the export value of a Salesforce field, Microsoft Word has the ability to make text in your document dynamic. As an example, you can have a checkbox appear in Microsoft Word instead of a text string. You can also have tables, paragraphs or tables of data appear based on a Salesforce field.

For example, in an Account record, the Account Record Type has a value of Partner, but we want a sentence to appear in the Microsoft Word document when Partner is merged into the document. Also, in the same record, Employees has a value of 100, but we want a box to be checked or unchecked if the value in the Employees field is greater than 50.

Insert a field in Microsoft Word

The first step toward making the text in your Microsoft Word document conditional is Inserting a Field to the document.

To do this navigate to Insert - Quick Parts - Field within Microsoft Word. This will initiate the Field menu.

Most conditional text can be performed with an IF field. Select IF in the Field names: list. Then enter in a formula in a Field codes: area. The syntax of the Field codes: is dependent on whether you are evaluating text or numbers.

Evaluate numbers with an If formula

If you are evaluating numbers, then you must exclude quotes from the evaluation portion of the IF formula (<<Account_NumberofEmployees>> > 50), but include quote in the true ("T") and false ("F") statements .

Even though quotes ("") are excluded from the evaluation portion of the IF formula, you must include them for the true and false statements. Once your formula is set, select the OK button.

If you want a checkbox to display instead of text you can always insert a Wingdings 2 symbol

You can view your field code by right clicking on the true or false and selecting the Toggle Field Codes option.

Above you can see our field code. If the number of employees is greater than 50, a checked box will appear, if there are 50 employees or less, a unchecked box will appear

Evaluate text with an IF formula

When evaluating text, you must include the Salesforce merge tag and a value in quotes ("Value").

In the IF formula above, the evaluating portion of the formula is surrounded with quotes ("") as well as the true and false statements. When ready, navigate to a record on your starting object and complete all steps in the generate documents page and run the DocGen Package.

We can also merge in the RecordType and Employees fields into our word formulas.

Above is the output with the word formulas highlighted.

Note:  For more information on using IF field in Microsoft Word, see Field codes: IF field on the Microsoft site.

Related information

Add dynamic images to output

Row replication in Microsoft Word

Tagging a Microsoft Word document