Functions supported in scripting
There a
few built-in functions supported in scripting. These functions can be nested within functions
also like trim(toUpperCase($StringVariable))
.
String manipulation functions
These examples are written with variable $StringVariable
but any string
could be used instead:
- Concatenation: String Concatenation could be done $StringVariable = $StringVariable1 + " " + $StringVariable2 or concat($StringVariable1, $StringVariable2).
- UpperCase: Converting a string to uppercase. For example, toUpperCase($StringVariable) or $StringVariable = toUpperCase("Hello World");
- LowerCase: Converting a string to lowercase. For example, toLowerCase($StringVariable)
- Trim: Removing whitespace from both ends of a string. For example, trim($StringVariable)
- Replace: Replacing parts of a string with another string. For example, replace($StringVariable, "World", "Infor")
- Substring: Extracting a portion of a string. The start Index is optional parameter. For example, substring($StringVariable, startIndex = 0, endIndex)
- Length: Getting the length of a string. For example, length($StringVariable)
- IndexOf: Finding the index of a substring within a string. Returns the first index instance of substring or returns -1. For example, indexOf($StringVariable, "Hello")
- Contains: Checking if a string contains a specific substring. Return True/False. For example, contains($StringVariable, "Hello")
Mathematical operations
These are the operations available:
- Addition, Subtraction, Multiplication, Division, Modulo: These
basic arithmetic operations are available:
- $NumberVariable = $NumberVariable1 + 15;
- $NumberVariable = $NumberVariable1 - $NumberVariable2;
- $NumberVariable = $NumberVariable1 * $NumberVariable2;
- $NumberVariable = $NumberVariable1 / $NumberVariable2;
- $NumberVariable = $NumberVariable1 % $NumberVariable2;
- FormatNumber: This function is used to format a numerical value to a specified number of decimal places. This is particularly useful for ensuring consistent numerical precision in your documents or when you need to round numbers for display purposes. For example, $formattedNumber = formatNumber($NumberVariable, 2); If $NumberValue is 3.14159 then $formatedNumber will be 3.14.
Boolean logic
Logical operations with Boolean Variables, where Contition1 and Condition2 evaluate to a boolean value. These are the examples:
- $BooleanVariable = (Condition1 && Condition2);
- $BooleanVariable = (Condition1 || Condition2);
These are the comparison operators:
- <: Less than
- >: Greater than
- ==: Equal to
- !=: Not equal to
- <=: Less than or equal to
- >=: Greater than or equal to
These are the logical operators:
- && or &: Logical AND
- || or |: Logical OR
Brackets for priority: ( and ) brackets can be used to change the precedence of operators, allowing certain conditions to be evaluated before others. This is particularly useful for complex conditional expressions where the order of evaluation matters.
Conditional logic and control flow
If, Else, Else If Conditions: These direct the flow of the script based on conditions:
- Using logical operators and comparison operators within if/else conditional statement.
- Also allow the use of brackets () to evaluate a certain condition before the other one.
- The If/else if/else condition must be written in the respective order like in other programming languages.
- It is necessary to include the curly parenthesis { }, even when there is one statement below a condition.
if (($variable1 == $variable2) && ($variable3 < $variable4)) {
// Actions to perform if both conditions are true
} else {
// Actions to perform if any condition is false
}
$priceItem3 = xpath(/Parent/CostExample/Item3Price);
if (xpath(Item3) == "YES"){
if (toUpperCase(xpath(UserType)) == "PREMIUM"){
Number $discount = 0.20;
$priceItem3 = $priceItem3 * (1 - $discount);
$NumberofTimesDiscountApplied = $NumberofTimesDiscountApplied + 1;
}
else{
$priceItem3 = xpath(/Parent/CostExample/Item3Price);
}
$Item3Count = $Item3Count - 1;
$NumberofTimesDiscountNotApplied = $NumberofTimesDiscountNotApplied + 1;
}
else {
$priceItem3 = 0;
}
Content control specific operations
These options are available:
- XPath: There is an
xpath()
function that you could use the value from data xml. Thexpath
must evaluate correctly or else it would give an error. The value can be assigned to a variable$Nodevalue = xpath("/path/to/node");
- Font Size and Color: Adjusting the appearance of text dynamically
based on conditions or data values. These functions are available:
- setFontSize(Number size): Sets the font size of the current text run to size.
- setFontColor(Integer r, Integer g, Integer b): Sets the font color of the current text run using RGB values.
- setFontColorByName(String colorName): Sets the font color of the current text run based on a color name.
- ClearContent: Hide the Content Control using
clearContent()
based on certain conditions or user actions. For example, a section of the document is only relevant if certain conditions are met (xpath value evaluates to certain value that is not to be displayed). If those conditions are not met, clearContent() can be invoked to clear the section.