Business Rule action
What is it? A business rule is an action type that allows you to configure a script on a BPMN task node. When the process instance token reaches this task, the defined script will be executed.
Why is it useful? The script can read and write the data available on the process at the moment the script is executed. For this reason, it is very important to understand what data is available on the process when the script is executed.
Business rules can be attached to a node by using actions with action rules on them. These can be specified using DMN rules, MVEL expressions, or scripts written in JavaScript, Python, or Groovy.
»Supported scriptsYou can also test your rules by using the Test Rule function.
Example
Let's take look at the following example. We have some data about the gender of a user and we need to create a business rule that computes the formal title based on the gender:
This is how the process instance data looks like before it reaches the business rule
{
"application" : {
"client" :
{
"firstName" : "David"
"surName" : "James"
"gender" : "M",
}
}
}When the token reaches this node the following script (defined for the business rule is executed). The language used here for scripting is MVEL
if(input.?get("application.client.gender")== "F"){
output.put("application.client.salutation", "Ms");
} else if(input.?get("application.client.gender")== "M") {
output.put("application.client.salutation", "Mr");
} else {
output.put("application.client.salutation", "Mx");
}After the script is executed, the process instance data will look like this
{
"application": {
"client": {
"firstName": "David",
"surName": "James",
"gender": "M",
"salutation": "Mr"
}
}
}
⚠️ Flattened vs unflattened keys
With version 2.5.0 we introduced unflattened keys inside business rules. Flattened keys are now obsolete. You are notified when you need to delete and recreate a business rule so it contains an unflattened key.
- Here is an example of a flattened key inside a business rule:
Example for deprecated versions previous to v2.5.0
def createActionForCustomer (name, cnp)
{
return{
"name":name,
"cnp":cnp
}
}
String cif = input.get("clientIdentification.cif");
output.put("clientIdentification.personalIdentifactionNumber",cif)
output.put("identificationData", createActionForCustomer("action1",input.get("clientIdentifaction.cnp")));
- Here is an example of an unflattened key inside a business rule:
Example available for v2.5.0 version and higher
def createActionForCustomer (name, cnp)
{
return {
"name": name,
"cnp": cnp
}
}
String cif = input.clientIdentification.cif;
output.put("clientIdentification", {"personalIdentificationNumber": cif} );
output.put("identificationData", createActionForCustomer("action1", input.clientIdentification.cnp));
For more information about each type of Business Rule Action, check the following sections:
»DMN Business Rule Action