The context in which a rule is called, and the context in which the rule terms are evaluated, have a significant impact on the resulting rule processing and rule terms.
The context of a rule definition describes where the rule is being used within the application at run time. The context is set by the definition referencing the rule within the application project and that calls the rule at run time. Included in the context of a rule’s usage are the definition referencing the rule, the data type expected to be returned by the caller of the rule, data definitions such as objects, transactions, properties, and others that are in scope when the rule is called and how other data definitions are related to those within the application’s overall data structure.
In addition to the caller of the rule, each function within the rule definition will also have an impact on the context, specifically on those rule terms passed to the function as parameters. A given function can dictate the context of the terms used as its parameters including what data definitions are in scope and what data type is expected of the term being evaluated as a function parameter.
- Return Type - Rule function terms do not have a set return data type. Rather, functions support one or more data types for their return values. The caller of the function will dictate which data type is to be returned, and the function will provide a value in that data type. If the function does not support the data type being asked for, the null equivalent of that data type is returned by the function.
- Target Paths - Any target paths within a rule are affected by that rule’s context. If the property of an object is included in a rule, how that property is found and its value returned is affected by the context of the rule. A rule that contains a reference to an object property will not likely be one that can be reused for a different object. The target path to the property will be invalid.
- Rule Function Behavior - Many rule functions will behave differently based on the context in which the function is called. These differences can include both the data type of the function’s parameters as well as how the function processes those parameters. Many functions with numeric parameters will evaluate those parameters as the same data type for which the function is being asked. A given function, then, can evaluate its parameters as integral numbers in one context and decimal numbers in another. Other functions may perform different processing in different contexts based on the data type of each context.
To define the term more precisely, context is the way in which a rule and its terms are called and that affects the behavior, data types, and target path resolution when that rule is evaluated at run time. Context plays a role in the evaluation of each term within a rule, including function terms, data terms , and sub-rule terms.