Using Conditional Clauses and Text (Pre-FX2)
One of the key advantages of using the Apttus Contract Management Suite is the ability to use conditional clauses and text within contract templates. The Apttus Merge Server resolves these conditions at run time when the draft document or final agreement document is generated, but X-Author is where you create and maintain these conditional clauses.
Conditional clauses makes use of the built-in features of Word’s conditional text processing. X-Author extends the built-in features of Word to provide support for conditional clauses within Word template documents.
You must have field codes enabled in Word when using conditional text processing. Select Alt-F9 to toggle field codes on and off.
General Structure
The structure of a conditional expression uses the IF syntax of Word and is as follows: { IF Expression1 Operator Expression2 TrueResult [FalseResult] }
The field brackets ({ }) are used to delimit conditional expressions from normal text. These field delimiters cannot be typed in but are entered using Ctrl+F9. Square brackets ([ ]) denote optional arguments.
Expression1 and Expression2 are values you want to compare. These expressions can be names, text strings, numbers, nested fields that return a value, or mathematical formulas. If an expression contains spaces, enclose the expression in quotation marks.
Operator is the comparison operator with a space before and after it. It can be one of the following types:
Operator |
Description |
---|---|
= |
Equal to |
<> |
Not equal to |
> |
Greater than |
>= |
Greater than or equal to |
< |
Less than |
<= |
Less than or equal to |
TrueResult and FalseResult can be either text or a nested IF field that result whenever the comparison is true (TrueResult) or false (FalseResult). If FalseResult isn't specified and the comparison evaluates to false, the IFfield has no result and returns nothing. Each string containing multiple words must be enclosed in quotation marks.
If the operator is '=' or '< >' Expression2 can contain a question mark (?) to represent any single character or an asterisk (*) to represent any string of characters. Expression2 must be enclosed in quotation marks so that it's compared as a character string. If you use an asterisk in Expression2, the portion of Expression1 that corresponds to the asterisk and any remaining characters in Expression2 cannot exceed 128 characters.
Special Operators
Due to restrictions with the built-in conditional text processing capabilities of Word, there is no native support for a “contains” operator.
This is of particular importance when entering conditional expressions to test Salesforce multi-picklist data types that can contain multiple values for the presence of a particular value. For instance, the conditional expression
{ IF { MERGEFIELD City } CONTAINS "Fran" "contains Fran." "does not contain Fran." }
where we wanted to see if the merge field City contained the characters Fran is not possible. If for example the city could be San Diego, San Francisco, or San Jose we would not be able to test successfully for San Francisco.
In addition, it is NOT possible to reword this conditional expression as
{ IF { MERGEFIELD City } = "*Fran*" "contains Fran." "Does not contain Fran." }
using before and after wildcard characters since they are not supported together. Using a wildcard character after text, as in “Starts With”, or before text, as in “Ends With” is possible, but not both. Thus we can have “testval*” (for Starts With ‘testval’) or “*testval” (for Ends With ‘testval’) in an expression, but not “*testval*”.
To get the functionality of a CONTAINS operator, you MUST use the make conditional command and select CONTAINS as the operator. This adds some special tags to the conditional expression so it can be evaluated correctly at runtime.
Conditional Clauses
X-Author provides support for two basic types of conditional text: inline conditional text and conditional references. Conditional inline text contains the condition with the actual text to be inserted if the condition is true. A conditional reference contains the same condition but contains a reference to the text (which can itself contain additional conditional text).
The advantage of using a conditional reference is that the text that gets inserted for a true condition at runtime comes from the clause reference in Salesforce which can be changed independently of the contract template. Inline conditions, on the other hand, are a permanent part of the contract template and cannot be changed independent of the template itself.
Rather than hard coding the text, using a conditional clause reference allows you to include the text at run-time instead of when the template is created. This offers significant advantages since using a clause reference will allow you to dynamically include the latest version instead of an older one.
In order to use clause reference expressions you should always use the Make Conditional option. It automatically inserts the correct command and clause ID that allows the clause to be inserted at runtime. Constructing conditional references manually should be avoided. The differences between using inline clauses and clause references are as follows:
Using a Clause Reference:
{ IF { MERGEFIELD A } = "True"
"{ CLAUSEREF id=00P50000001hqyEEAQ name=SampleClauseA" "" }
Using an Inline Clause:
{ IF { MERGEFIELD B } = "True" "Hard coded clause text to be inserted" "" }
There are two ways to specify conditions. You can enter conditional expressions using the Make Conditional option or by typing it manually into the document enclosed by field brackets using Ctrl+F9 characters or via the Insert Field menu using a MergeField.
For marking a simple block of text as conditional, the Make Conditional command is easier to use. However, it is currently limited in the complexity of the expression it can create due to ambiguities in the expression that can be present.
For complex expressions, it is recommended you enter the basic expression first, using the Make Conditional option, and then refine it by directly editing the text within the conditional field brackets. One other current drawback Author is that once a condition is created using the Make Conditional command, it cannot be selected and edited again via the Make Conditional option. All future edits must be made manually.
Conditional Text Examples
The IF field (field: A set of codes that instructs Microsoft Word to insert text, graphics, page numbers, and other material into a document automatically. For example, the DATE field inserts the current date.) performs one of two alternative actions, depending on the condition you specify.
For example, the statement "If the weather is sunny, we'll go to the park; if not, we'll go to the movies" specifies a condition that must be met (sunny weather) for a certain action to take place (going to the park). If the condition is not met, an alternative action occurs (going to the movies).
The following IF field is a similar type of statement. If the current data record contains "San Francisco" in the City field, Word prints the first text in quotation marks in the merged document that results from that data record. Otherwise, Word prints the second set of text. This example uses the IF and MERGEFIELD fields together.
{ IF { MERGEFIELD City } = "San Francisco" "Please call our local office." "Please return the enclosed form in the provided envelope." }
You can modify the IF field codes by using them in conjunction with other field codes, such a comparing a data field with another data field or bookmark: This IF field compares the number in theRatedata field with the number in theDiscountdata field. If the numbers are equal, the specified text is printed. If they are not equal, not text is printed.
{ IF { MERGEFIELD Rate } = { MERGEFIELD Discount } "We will offer you a larger discount. " " " }
Performing Boolean AND/OR Operations
The IF field does not directly support Boolean AND and OR operations in a template. However, the logical AND and OR operators are actually just abbreviations of nested IF statements; therefore, you can construct the equivalent of Boolean AND and OR operations.
Starting with the basic IF statement
{IF test1 "TrueResult" "FalseResult" }
You can nest another IF statement to create a logical OR or AND statement as in the following:
To create an OR statement (Position the second test inside the second set of quotation marks):{IF test1 "TrueResult" "{IF test2 "TrueResult" "FalseResult" }" }
To create an "AND" statement (Position the second test inside the first set of quotation marks):{IF test1 "{IF test2 "TrueResult" "FalseResult" }" "FalseResult" }
Constructing a Boolean AND Statement
The AND statement
IF (field <> "A") AND (field <> "B") THEN "TrueResult"
ELSE "FalseResult"
END IF
can be translated to an IF statement for use in a template as follows:
{IF field <> "A" "{IF field <> "B" "TrueResult" "FalseResult" }" "FalseResult" }
Constructing a Boolean OR Statement
The OR statement
IF (field = "A") OR (field = "B") THEN "TrueResult"
ELSE "FalseResult"
END IF
can be translated to an IF statement for use in a template as follows:
{IF field = "A" "result" "{IF field = "B" "TrueResult" "FalseResult" }" }
You can specify multiple conditions by nesting a COMPARE field inside an IF field.
To type field braces ( { } ) in a Word document, press Ctrl+F9. To turn field codes on or off, press Alt+F9.
Complex Conditional Expressions
Here are several examples of creating more complex conditional expressions illustrating what we’ve seen so far. These examples show how simple expressions can be combined together to form much more complex expressions. Although parentheses are not directly support in the conditional language, we also show how you can simulate them. The expressions below are real and contain real fields so you can copy and paste them from this document into a real template if you wish (you’ll have to change the merge field names of course). An understanding of Boolean logic is assumed.
Multiple OR Conditional Expressions
Here is an example of a complex conditional expression combining multiple OR operators. For this expression to evaluate to true, AT LEAST ONE of the component expressions must be true. To simplify these expressions for illustration purposes, a clause reference is used instead of inline text.
A or B or C or D
Alternative 1
{ IF {=(
{ IF { MERGEFIELD A } = "True" 1 0 } +
{ IF { MERGEFIELD B } = "True" 1 0 } +
{ IF { MERGEFIELD C } = "True" 1 0 } +
{ IF { MERGEFIELD D } = "True" 1 0 }
) } >= 1
"{ CLAUSEREF id=00P50000001hqyJEAQ name=SampleClause }" "" }
Multiple AND Conditional Expressions
Here is an example of a complex conditional expression combining multiple AND operators. For this expression to evaluate to true, ALL of the component expressions must be true. To simplify these expressions for illustration purposes, a clause reference is used instead of inline text.
A and B and C and D
{ IF {=(
{ IF { MERGEFIELD A } = "True" 1 0 } *
{ IF { MERGEFIELD B } = "True" 1 0 } *
{ IF { MERGEFIELD C } = "True" 1 0 } *
{ IF { MERGEFIELD D } = "True" 1 0 }
) } >= 1
"{ CLAUSEREF id=00P50000001hqyJEAQ name=SampleClause }" ""}
Multiple Complex Conditional Expressions
Multiple AND and OR expressions are fairly simply to setup and use since the order of evaluation at execution time does not matter. In other words, the expression “A and B and C and D” evaluates to the same thing as “A and C and B and D”. This is also true for complex OR an expression since only one is required to be true for the result to be true. There are two ways you can construct conditional expressions: implicitly or explicitly. This is important because of the way the conditional expression evaluator evaluates all expressions at runtime.
Implicit Evaluation
Here is an example of a complex expression with implicit evaluation order (in other words without explicitly defining the order of evaluation). If you use implicit evaluation, you must be careful to make sure the expression evaluates to what you think it should since the expression will be evaluated from left to right. This complex expression is basically the same the multiple AND and OR samples except that we use the “+” arithmetic addition operator for a logical OR operation and the “*” multiplication arithmetic operator for logical AND operations. Alternating + and * we then get the expression:2
((A or B) and C) or D)
Alternative 1 – Uses Implicit Evaluation from Left to Right
{ IF {=(
{ IF { MERGEFIELD A } = "True" 1 0 } +
{ IF { MERGEFIELD B } = "True" 1 0 } *
{ IF { MERGEFIELD C } = "True" 1 0 } +
{ IF { MERGEFIELD D } = "True" 1 0 }
) } >= 1
"{ CLAUSEREF id=00P50000001hqyJEAQ name=SampleClause }" "" }
Explicit Evaluation
Here is a better example of the way you should construct complex expressions with explicit evaluation order since there is no way the expression can be misinterpreted. Using this method is a little trick, but it ensures the expression evaluations to exactly what you think it should.
(A or B) and (C or D)
Alternative 2 – Uses Explicit Evaluation
When constructing complex Boolean expressions containing multiple AND and OR operators, you can only compare two arguments at a time, thus the following example DOES NOT work:
{ IF {=(
{ { IF { MERGEFIELD A } = "True" 1 0 } +
{ IF { MERGEFIELD B } = "True" 1 0 } } *
{ IF { MERGEFIELD C } = "True" 1 0 } +
{ IF { MERGEFIELD D } = "True" 1 0 } }
) } >= 1
"{ CLAUSEREF id=00P50000001hqyJEAQ name=SampleClause }" "" }
If we modify the expression to include steps that force the comparison of the two arguments ‘(A or B)’ and ‘(C or D)’ followed by a final comparison of the two results using the "*" operator (AND) then we get the correct expression that DOES work:
{ IF {=(
{ =({ IF { MERGEFIELD A } = "True" 1 0 } +
{ IF { MERGEFIELD B } = "True" 1 0 }) >= 1 } *
{ =({ IF { MERGEFIELD C } = "True" 1 0 } +
{ IF { MERGEFIELD D } = "True" 1 0 }) >= 1 }
) } >= 1
"{ CLAUSEREF id=00P50000001hqyJEAQ name=SampleClause }" "" }
If you study the two different expressions above carefully, you will see that the subtle nuance in how you construct the expression makes all the difference in how the expression gets evaluation at runtime by the conditional expression engine. The point here is that you should use explicit order of evaluation when possible and constrain your comparisons to two or more sub expressions at a time.
Summary of Word field related commands
The following Word shortcut keys can be used to toggle features.
Field Commands |
Keystrokes |
---|---|
Insert field brackets { } |
[Ctrl] [F9] |
Toggle field codes |
[Alt] [F9] |
Force a field update |
[F9] |
Lock a field |
[Ctrl] [F11] |
Unlock a field |
[Shift] [Ctrl] [F11] |
Field to plain text |
[Shift] [Ctrl] [F9] |
Customizable Expressions
The following conditional expressions consist of actual Microsoft Word fields and can be copied from this document and pasted into contract or clause templates for further customization. Note that the clause reference IDs will need to be changed or the reference field can be deleted and simple text can be used. To see these fields, toggle ALT-F9 in the Word document version of this guide to make the merge field codes appear or disappear.
Multiple OR Conditional Expressions
A or B or C or D
Multiple AND Conditional Expressions
A and B and C and D
Multiple Complex Conditional Expressions
(A or B) and (C or D)