Rule variables
A rule variable is a name to which you assign a value. You define the variable in the definitions part of a rule, and you can use it only in the
condition and action parts of the rule that declares the variable.
Rule variables can make your rules easier to build and understand by simplifying terms.
Making rules easier to understand
You might find parts of a rule difficult to understand. For example, the following rule uses the
term of to chain together business terms:
if the value of the shopping cart of customer is less than 100 then...
You can shorten this chain of words by using a rule variable. For example, you can define a
variable named cart to represent the business terms
shopping cart and customer:
definitions set cart to the shopping cart of customer; if the value of cart is less than 100 then...
One rule per rule variable
The scope of a variable is the rule that declares the variable. The name of the variable must be unique in the rule. After you define a variable, it can be used in any part of the rule.
In the following rule, the definitions part defines
the variable Smith, which is then used in the if part of the rule.
definitions set Smith to a customer in customers; if the category of Smith is Gold then set discount to 10;
When rule variables do not match data
A rule can define a rule variable that data cannot satisfy when an application calls the
decision. For example, you might define a variable named 'low
risk borrowers' for all the borrowers whose credit score is at least 200. However, when you
run the rule against data from an application, the rule might not find any borrowers who match the
rule variable. In this case, the rule variable behaves as a condition, and the rule cannot execute
the actions in its then and else parts.
Restrictions on rule variable names
Do not use the following characters in the names of your variables:
| Character | Description |
|---|---|
| TAB | Tabulation |
| \n | Line break |
| ' | Single quotation mark |
| " | Double quotation mark |
| () | Opening and closing parentheses |
| / | Slash |
| , | Comma |
| ; | Semicolon |
| ’ | Curly quotes |
Single quotation marks
If the name of a rule variable contains one or more spaces, you must enclose the name in single quotation marks when you define or use the variable. If a variable name contains only one word, quotation marks are optional.