In Bizagi you can reuse business rules to make your automation process more efficient. Business rules that are used frequently in a project are only created once and then they only need to be associated to the new elements when they are required.
You need to know where to create those business rules to be able to reuse them.
Types of business rules
There are two types of business rules: Boolean rules and Scripting rules. Each type provides the flexibility and ease of use so their development is as powerful and yet as friendly as possible. Depending on where you use business rules, Bizagi will provide one or the other.
These rules must only return True or False. As we saw in previous sections, Boolean rules are used in:
oRules associated with sequence flows (to route the Process).
oRules used as conditions for attributes (fields in the forms) to be (or not) visible, editable or required.
Notice the Reusable checkbox on the lower left corner. If the rule can be reused, tick the box.
These rules are the ones that perform calculations and validations. In these rules you can type code to carry out any type of task; they do not have to return any type of data in particular. These rules are used in:
oOn Enter, On Save, On Exit actions
oValidations performed on Tables in Forms
oButtons on Forms
This rules are always reusable. Depending where it is created it can be reused by any Process in the whole project, by any Process within the same application, or just by the same Process.
Bizagi has four levels where Business rules as saved and according to that they can be accessed to be reused.
The levels are:
These can be Boolean and Scripting rules. They are general rules that can be accessed and reused by all Processes in all applications, so they usually perform calculations that apply to several Processes, with no context. You can create families of rules to order them. If the rule is created as Function it will be used as library rule. This way, it can be called upon other rules to perform calculations.
These can be Boolean and Scripting rules. They can be accessed and reused by all Processes in a single application. They usually perform general calculations that can apply to Processes that share a context. You can create families of rules to order them.
•Entity rules: these can be boolean and scripting rules. They can be accessed by any Process in any application as long as the entity where the business rule is saved is part of the data model. The boolean rules in entities manage whether or not controls are visible, editable or required. Scripting rules are attached to buttons and validate Tables.
•Process rules: these can be Boolean and scripting expressions. They can be reused exclusively by the Process; any other Process will not be able to 'see them' to be reused. The Boolean rules are the ones related to the routing of the Process. Scripting rules are the ones related to On Enter, On Save and On Exit actions. When you create your rules to route the Process or On Enter, On Save and On Exit actions, through the fourth step of the Process wizard, these rules will be automatically created as Process rules.
Suppose you work in a bank. When an applicant of a loan makes a request, you want to default the receive date. This way you ensure that when a new case is created, the Request date is defaulted to today.
In another process, Purchase Request, you need to set an minimum valid date for the delivery: It has to be later than today, because a delivery date can only be from the next day onwards.
Since there are different scenarios that need to check against the current date (today), it makes sense to create a single business rule and reuse it throughout all the processes.
Note that this rule doesn't need any context. There is no data model manipulation, just today's date.
Thus, we create a Global rule that returns Today's Date using the function on the Duration-Date category.
In the Expert view go to Business Rules. Right-click Expressions under the Business Rules classification and select New Scripting Expression.
If you have Families of rules created you can allocate this rule to a family in the Rule Family drop-down list, or leave it blank.
We can use this rule in the Forms Modeler for any Process, to set a Default value, or a minimum/maximum date.
Open the Forms Modeler, select the attribute where you wish to relate the rule. Select default value and choose the rule.
For the loan application, you need to provide some initial information about the applicant. Before the applicant is accepted as a client, the forms will need to show or hide some controls. Thus, you need a visibility rule that can be used in several forms of the same process.
Note that this rule has a context, because it relates to the applicant of the request. Thus, the context will be the Process Entity of the parent process. Thus, we create an application rule that returns True or False according to the customer evaluated.
In the Expert view go to Business Rules. Right-click Expressions in the Application where you wish to use your rule. Select New Expression.
You will be asked to decide between a Boolean and a Scripting rule. In this case we select Boolean.
Drag and drop the data to evaluate and select the condition.
Finally give your rule a name. If you have Families of rules created you can allocate this rule to a family in the Rule Family drop-down list, or leave it blank.
We can use this rule in the Forms Modeler for a Process in the chosen application.
Open the Forms Modeler, select the attributes that you wish to hide if the applicant exists as client.
Example of an Entity rule
In a Purchase Request Process there is a collection of products, where the end user enters all the products needed.
There is a one-to-many relationship between the Process Entity, Purchase Request, and Products Requested.
The end user enters each product specifying the unit price and the quantity. Then, when the record is saved, it is necessary to calculate and display the total price of the product, that is, the unit price times the quantity.
We calculate this amount using an Edit Validation Expression. These rules are related to the Forms modeler where they are automatically saved in the collection entity. Thus, they can be reused by any Process that also has the collection entity in its data model.
In the Forms modeler select the Table where the rule will be placed.
Select the Edit validation expression. This will open a scripting rule to write the code. Note that since we are working over a collection the context of the rule will be the collection entity, in this case Products Requested.
When the end user saves the new product, the total price will be calculated.
Example of a Process rule
Bizagi will store as Process rules the one created On enter, on exit, on save and the routing rules.
The following rule is a Boolean process rule that routes the Purchase Request process when the supervisor has requested changes, before it can continue to the Quotation Sub-Process.
How to reuse a rule
When a rule has been created and you want to reuse it, go to the sequence flow where you want to associate it and open the expression manager.
Select Based on the result of an expression.
This will display all rules available to be reused, in the expressions tab.
Select the one you want and click OK.