<< Click to Display Table of Contents >> Library Rules |
Overview
There are common situations where a business rule or expression can be used in different scenarios across a same project, to perform a specific capability. To avoid the need of rewriting the same rule or expression in each of those scenarios, Bizagi features Library Rules.
Library Rules (also known as Global Rules), can be reused across all applications and processes contained in one same project, in each of those situations. This way, users developing processes will only write the rule once and associate it wherever they might need it.
Applicability and concepts
Some examples of Library Rules are: obtaining today's date, obtaining the case creator's ID, or validating if a given date is a holiday.
Library rules work just as business rules, but they do not have a context associated to them since they can be invoked from anywhere on the project. This means that from Library rules there is no access to the Data Model, thus XPaths can't be used.
Keeping library rules organized
In some projects many library rules may be needed, potentially creating a difficulty to identify the specific rule someone needs and maintaining the rules updated. In order to keep all your library rules organized, it is encouraged to use Expression families, which let you to create groups of rules.
Therefore, before actually starting to create a Library rule, you should first create an Expression family.
To use this option, go to the Expert view, Business Rules options, Library Rules node and click the New expression family option.
A window prompting for a name for your new Expression family appears.
Input the desired name and click OK.
Then on the main panel you will see your newly created Expression family.
For example, if the name you inputted was "Date", the result will be as follows.
Inside each family, any number of rules can be added.
Creating Library Rules
Library rules can be created independently or as part of an already existing Expression family. In order to create a standalone rule, click the New library rule option, next to the New expression family option. If you wish to add a rule as part of a family, right click the family and select the New library rule option that is displayed on the menu.
Either way, a similar window to the one shown below is displayed.
There you can build your rule, similarly to what you would do when building an expression.
You should set a Display name (and a name), a Description, select the family you wish to add the rule to (note that the one previously selected will be shown by default), the Return type, and Parameters.
Then, build your rule as you would normally do in an expression editor.
Remember that when building library rules there is no Context, which means that the Data Model cannot be seen, meaning that XPaths cannot be used. Thus, avoid the use of any Xpath function or Me, such as Me.getXPath, or Me.newCollectionItem, or <count(XPath)> |
Using library rules
When you have already set up a Library rule, you might want to use it during some point of a process.
Wherever expressions are available to be used in Bizagi, then the library rules can be used and leveraged.
To do so, click the Library rules option on the expression editor, as shown below.
A window with a tree view with all the Library rules set on the project is shown.
Notice how they are organized by Expression family.
Select the rule you wish to add, and click OK.
A pop-up window appears, and in there you should specify where the value returned by the Library rule should be stored.
There are two different ways to choose how to store the return value of the Library rule, two different places to store the output:
•The first one is the button with a pencil Icon, which lets you to choose an existing variable or create a new one.
As hinted, this one lets you to store the output in a variable for later use.
•And the second one, the button with a diagram Icon vertically flowing, lets you to choose an attribute from the Data Model to store the value.
This one lets you to directly store the output into an attribute of a given Entity of your Data Model.
The third button simply clears what you have set up previously, in case you wish to perform a change or adjust any previous configuration. |
In either case, the resulting configuration is seen as an assignment instruction, just as programming languages commonly handle them.
An assignment instruction where on its left part, it displays the Data Model's attribute or variable storing the output.
And on the right part, it features the actual invocation of the Library rule, while having any inputs sent to it, inside of parenthesis.
The following image displays an example, having specifically the Me object sent as an input, and having its output stored in a variable called vDate.
Examples
Rely on the following two examples for additional guidance.
Example 1 - Today's date
Suppose you work in a bank and that whenever an applicant of a loan makes a request, you want to set the receive date.
This way you make sure that whenever a new case is created, the Request date is defaulted to "today".
Now in another process, Purchase Request, suppose 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 have a date be checked and compared to the current date (today), it makes sense to create a single business rule and reuse it throughout all points of processes needing such validation.
Note that this rule doesn't need any context.
There is no data model manipulation, it is a matter of just sending today's date and receiving concluding information.
To resolve the above, 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. Make sure that this rule returns a value.
Notice that this example returns the value contained in vDate.
Last Updated 2/1/2023 3:54:39 PM