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.

Business rule action

For more information about supported scripting languages, see the next section:

Supported scripts

You can also test your rules by using the Test Rule function.

Configuration

To use a Business Rules Action, follow these steps:

  1. Select a BPMN Task Node: Choose the BPMN task node to which you want to attach the Business Rules Action. This could be a Service Task, User Task, or another task type that supports actions.
  2. Define the Action: In the task node properties, configure the “Business Rules Action” field and select the desired language (MVEL, Java, JavaScript or Python).
  3. Write the Business Rule: In the selected language, write the business rule or decision logic. This rule should take input data, process it, and possibly generate an output or result.
  4. Input and Output Variables: Ensure that the task node can access the necessary input variables from the BPMN process context and store any output or result variables as needed.
  5. Execution: When the BPMN process reaches the task node, the attached Business Rules Action is executed, and the defined business rule is evaluated.
  6. Result: The result of the business rule execution may affect the flow of the BPMN process, update process variables, or trigger other actions based on the logic defined in the rule.

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:

  1. This is how the process instance data looks like before it reaches the business rule:

    {
        "application" : {
            "client" : 
            {
                "firstName" : "David",
                "surName" : "James",
                "gender" : "M",
                
            }
        }
    }
    
  2. 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.application.client.gender == 'F') {
    output.put("application", {
        "client": {
            "salutation": "Ms"
        }
    });
} else if (input.application.client.gender == 'M') {
    output.put("application", {
        "client": {
            "salutation": "Mr"
        }
    });
} else {
    output.put("application", {
        "client": {
            "salutation": "Mx"
        }
    });
}
  1. 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.

Obsolete business rule

Business rules examples

Examples available for v2.5.0 version and higher

We will use the MVEL example used above to rewrite it in other scripting languages formats:

if (input.application.client.gender == 'F') {
        output.put("application", {
            "client": {
                "salutation": "Ms"
            }
         });
    } else if (input.application.client.gender == 'M') {
        output.put("application", {
            "client": {
                "salutation": "Mr"
            }
         });
    } else {
        output.put("application", {
            "client": {
                "salutation": "Mx"
            }
        });
    }

For more detailed information on each type of Business Rule Action, refer to the following sections:

DMN Business Rule Action