Using advanced logic in Microsoft Word templates

You can add advanced logic, such as conditional statements, to Word export templates for more complex exports.

See Creating Microsoft Word export templates for information about creating templates.

Using conditional statements

Use conditional statements to check if a condition is true and export information depending on the result. Conditional statements must start and end inside a foreach loop.

Note:  Formatted text fields cannot be used in conditional statements. You must use the plain text field code instead.

If statement

Use if statements to check if a condition is true and export information only if it is. The following example only exports the 'IMMEDIATE PRIORITY:' text and issue tag field value if the issue Priority field value is 'Immediate'.

<<foreach [in IS_LIST]>>

<<if [IS_PRIO == "Immediate"]>>

IMMEDIATE PRIORITY: <<[IS_TAGNM]>>

<</if>>

<</foreach>>

If/Else statements

Use if/else statements to check if a condition is true and export information if it is, and export different information if it is false. The following example exports the 'IMMEDIATE PRIORITY:' text and issue tag field value if the issue Priority field value is 'Immediate'. If the Priority field contains a different value, the 'Normal priority:' text and tag field value are exported instead.

<<foreach [in IS_LIST]>>

<<if [IS_PRIO == "Immediate"]>>

IMMEDIATE PRIORITY: <<[IS_TAGNM]>>

<<else>>

Normal priority: <<[IS_TAGNM]>>

<</if>>

<</foreach>>

If/Else If statements

Use if/else if statements to check if a condition is true and export information if it is, and export different information for other true conditions if it is false. The following example exports the 'IMMEDIATE PRIORITY:' text and issue tag field value if the issue Priority field value is 'Immediate'. If the Priority field value is 'High', the 'High priority:' text and tag field value are exported instead. If Priority is a value other than 'Immediate' or 'High', the 'Normal priority:' text and tag field value are exported.

<<foreach [in IS_LIST]>>

<<if [IS_PRIO == "Immediate"]>>

IMMEDIATE PRIORITY: <<[IS_TAGNM]>>

<<elseif [IS_PRIO == "High"]>>

High priority: <<[IS_TAGNM]>>

<<else>>

Normal priority: <<[IS_TAGNM]>>

<</if>>

<</foreach>>

Using operators

You can use the following operators in conditional statements.

== (Equals)

<<if [IS_PRIO == "Immediate"]>>

!= (Does not equal)

<<if [IS_PRIO != "Immediate"]>>

&& (And)

<<if [IS_PRIO == "Immediate"] && IS_TYPE == "Customer Issue"]>>

You can also use parentheses to group multiple conditions in a tag.

<<if [(Priority == "Immediate") || ((Priority == "High") && (DateCreated != "4/24/2016"))]>>

|| (Or)

<<if [IS_PRIO == "Immediate"] || [IS_PRIO == "High"]>>

Using variables

You can use variables for readability, especially when using nested foreach loops. The variable must be declared in the list tag. In the following example, 'issue' is the variable name.

<<foreach [issue in IS_LIST]>>

Summary: <<[IS_SUMM]>>

<<foreach [in IS_LINKED_ISSUE_LIST]>>

<<[issue.IS_DNUM]>> - <<[IS_LINKED_ITEM_IS_SUMM]>>

<</foreach>>

<</foreach>>