States and Functions in Business Rules

States and functions provide a way for you to organize business rules and define the sequence for processing rules. Each rule base must have at least one state—the initial state—before rules processing can begin.

The Rules tree lists states and functions alphabetically. The list of rules within each state and function are in the order in which you want them to execute.

States are containers for rules. You can add as many states as you need for each stage of your business. You can set up rules in the initial state. For example, rules that are applied to all new opportunities, or other object type, depending on the rule base. Depending on the conditions of rules in the initial state, you can transition the opportunity into another state to continue processing the rules in that state.

For example, you might want to evaluate each new opportunity and assign it to a specific sales group. You could add rules in the initial state that transition to states called Government Agencies, Educational Institutions, or Medical Groups, depending on the industry type of the organization. Those states could contain rules that are unique to opportunities in the different industries.

Functions are also containers for rules. Functions group sets of rules that you want to use in multiple places. You can set up many separate rules that call the same function, or set of rules. This reduces the number of individual rules you need. When a rule in one state calls a function, all the rules within that function are processed. After all the rules in the function are processed, the rules engine resumes processing in the original state with the next rule in that state.

Note: The primary difference between states and functions is what happens when the rules engine processes the last rule. When the last rule in a state is processed, the rules engine stops processing, unless it encounters a stop processing rule before the last rule or it transitions to a function or another state. When the last rule in a function is processed, the rules engine proceeds to the next rule in the state from which the function was called.

Functions are useful tools for grouping rules, avoiding duplication, and making maintenance easier, however you aren't required to use them in a rule base. You can still take advantage of the powerful features of business rules. You can add as many states as you need, based on the processes you want to automate, and then create rules within each state.