This is the third blog of my blog series on Business Rules Consumption Patterns. In earlier blogs, you saw Pattern 1 – which explains how business rules can be used directly and indirectly in your custom application (which can be deployed on-premise or on-cloud).
Pattern 2 – Decisions in Workflow, Integration and IoT
In Pattern 2, you will see how business rules can be used to abstract the decision logic in process orchestration scenarios. Here I will show you how to consume rules in workflow, cloud integration services and internet of things using different extension use cases. Let us start with scenario1.
Usage Scenario #1
Exposing decision logic as business rules from SAP Cloud Platform Workflow
There is a strong need to separate workflow and rules such that the business users or non-technical users can easily modify the rules without changing the process flow or code. Rule independence is the key here. It gives agility (time-to-market after updating business rules), business empowerment (separating business logic with application logic) and readability and maintainability (easier to read the code and solve complex problems). Business rules can be used inside workflow to extract the decision logic or making branching decision or control the access restrictions of the workflow step etc. So, while the workflow is all about HOW, WHEN and BY WHOM; business rules focusses on WHY of the process flow.
SAP Cloud Platform Workflow and Business Rules work harmoniously to provide an unmatched support to automate workflow. SAP Cloud Platform Workflow is a service that is available in Neo environment and can be accessed via trial or factory accounts in all SAP data-centres across the globe. For more information on modelling workflow and other interesting aspects, please follow the blog community tagged as SAP Cloud Platform Workflow.
Business rules service can be accessed in Workflow using a Service Task. The workflow engine invokes the RESTful rule service with host and credentials information maintained in the destination configured at SAP Cloud Platform.
… then shall we begin with the exercise? Ok!
- Assumption is that you know how to configure and model the workflow. If not, then follow the blogs from Muralidaran Shanmugham and Christian Loos to know more on it.
For this blog, I have taken an example of a rule with name DetermineEquipments. This rule is written to find out the list of equipment that can be assigned to a newly hired employee, of a company, based on his job characteristics like job-title, organisation, role etc.
The rule in question is already modelled and deployed in SAP Cloud Platform. Let me show you the glimpses of the rule artefacts as the screenshots.
To call the rule service from the workflow, all you need to know is the (a) project name, (b) rule service name and (c) input & output data objects. In this example, these are as follows:
- Project Name: OnBoarding
- Rule service Name: DetermineEquipment
- Input Data Object: Employee
- Output Data Object: EquipmentInfo
As mentioned above, SAP Cloud Platform Business Rule can be called from workflow using Service task. To configure a service task all you need to do is:
- Define a destination as shown
Note: The destination URL is for the bpmrulesruntime destination. The authentication mechanism is BasicAuthentication. User mentioned must have Business Rules Runtime–> RuleSuperUser role assigned to it. (For more information on how to assign the roles refer the official documentation)
- From the palette objects in the workflow editor, drag-and-drop a Script Task in the process where you want the rules to be called.
In this script task, you will construct the payload for the rule execution.
If your workflow context attributes are already SAME as the rules input data-object attributes then all you need to do is add __type__ (see line number 5) and set it back to the context. For Example, as shown below
- Next, drag-and-drop a Service Task after the script task and configure properties with the rule execution details.
Note: Path in the configuration is the public API used to invoke the rule.
The beauty is that you can pass on the exact workflow context or a subset of the workflow context as the input payload for the rule invocation. All you need to ensure is that the attributes of the input data object defined in the rules are EXACT match as available in the workflow context.
The result of the rule invocation is returned based on the output data object (defined in the rule) and can be appended in the workflow context via Response Variable as shown in the screenshot above
With these 3 simple steps, your business rule is integrated with the workflow. You can now deploy the workflow and test it from Monitor Workflow app. You will see the execution traces or any failures during rule invocation in the Execution Log of the Monitor Workflow app.
Sample Reference Application
There is an SAP Blueprint published with SuccessFactors scenario using Workflow and Business Rules. You can also download the content from GitHub. All the instructions to setup and use the scenario are available in the README file of GitHub project
SAP Cloud Platform Business Rules – Extensions and Consumption Patterns
Use SAP Cloud Platform Business Rules in your custom application
Embed Business Rules SAPUI5 control in your custom applications