Variable definitions are those whose value can be assigned in actions of rules. You can create variable definitions on primitive data types and Java objects.
For more information, see Definition
Consider a variable definition as follows:
Name |
Type |
Initial Value |
---|---|---|
interest rate |
int |
0 |
This variable definition can be used in an action in an if-then rule as follows:
If |
|
... |
|
Then |
|
Assign:: interest rate = interest rate + 10 |
Typical Uses
Many rules involve calculation of a crucial output parameter that is modified by other rules. In such cases the output parameters can be modified in those rules.
To calculate interest rate, you can create a variable definition as follows:
Name |
Type |
Initial Value |
---|---|---|
amount |
double |
0 |
The variable definition can be used in an action in an if-then rule as follows:
If |
|
... |
|
Then |
|
Assign :: amount = 10.5 Assign :: amount = amount + 5 |
Some actions may return intermediate values that need to be used as input for other actions. This can be achieved by using variable definitions.
Consider a variable definition as follows:
Name |
Type |
Initial Value |
---|---|---|
temp |
int |
0 |
This variable definition can be used as follows:
If |
|
... |
|
Then |
|
Assign :: temp = performaction1 () |
|
performaction2 (Temp) |
Clarifications
Variable definitions can be used in conditions. When variable definition used in Assign action cause the values of those variable definitions to change, then these definitions used in conditions are re-evaluated . Based on the outcome then rules are appropriately removed from or added to the firing queue. Firing queue represents a collection of actions of all satisfied rules that are to be fired by the rule engine