Skip to Content

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!

 

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:

  1. 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)

 

  1. 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

 

  1. 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

 

Related Blogs
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

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

  1. Ayush Mittal

    Hi archana,

    I am trying to Use my Business rule Service In Workflow Default launchpad sit, my Rule is validated and deployed but my workflows instance keeps on giving an error i am not sure what it is can you help.

    An unspecified error occurred. Contact support citing logId e0c28730-8992-4464-88c6-0989a6a4a808 and provide steps to reproduce.
    Log ID: e0c28730-8992-4464-88c6-0989a6a4a808
    i am not sure what i can do is this a configuration error or a server error?
    thank you
    (0) 
    1. Archana Shukla Post author

      Hello Ayush,
      Can you please send me the screenshots of the execution log and the configuration of the your service task that uses rules. Have you ensured that the rule service you are trying to execute is running from POSTMAN or some other REST client

       

      (0) 
  2. Sruti Gupta

     

    Hi Archana,

    Thank you for this helpful blog.

    I am facing the same issue as Ayush.

    As I was unable to see the logs, so I raised a ticket and came to know the below error.

    “The XSRF token request to URL ‘https://bpmrulesruntimerules-xxxxxxxx.us2.hana.ondemand.com/xsrf-token‘ failed with HTTP status code 404″.

     

    I later changed the path to -> /v1/rules/xsrf-token, but still no luck.

    Can you guide what could be the issue?

    Below is the service endpoint from Monitor Workflows.

    https://bpmrulesruntimerules-xxxxxxxxx.us2.hana.ondemand.com/v1/rules/invoke?rule_service_name=MaterialQuantitySurcharge::SurchargeService

     

    Regards,

    Sruti

    (0) 
    1. Archana Shukla Post author

      Hello Shruti,

      In your case, it seems like you have not used destination and rules runtime relative URLs correctly.
      Let me explain again.

      Say you are trying to invoke the rule with project name as ShoppingCartPromotionRules and rule service name as DiscountRuleservice:

      1. You need to get the csrf token and the URL that forms based on your cloud platform tenant lets say is:

        https://bpmrulesruntimerules-af89653a.hana.ondemand.com/rules-service/v1/rules/xsrf-token

      Here the host is: https://bpmrulesruntimerules-af89653a.hana.ondemand.com
      relative URL to call the xsrf token is: /rules-service/v1/rules/xsrf-token

      2.  Similarly now to invoke the rules, the URL that forms is:

      https://bpmrulesruntimerules-af89653a.hana.ondemand.com/rules-service/rest/v1/rule- services/java/ShoppingCartPromotionRules/DiscountRuleservice

      Here the host is again: https://bpmrulesruntimerules-af89653a.hana.ondemand.com
      relative URL to invoke rule is: /rules-service/rest/v1/rule- services/java/ShoppingCartPromotionRules/DiscountRuleservice

      Now, if you want to call this rule in Workflow you need to create the Destination with BasicAuth. While doing so you can give the URL to Destination either

      (a) https://bpmrulesruntimerules-af89653a.hana.ondemand.com OR

      (b) https://bpmrulesruntimerules-af89653a.hana.ondemand.com/rules-service

      Depending upon the Destination you have configured, you need to give the relative URL in service task as follows:

      (i) If you defined destination as (a) then your service task URL will be:
      /rules-service/rest/v1/rule- services/java/ShoppingCartPromotionRules/DiscountRuleservice

      and token URL will be: /rules-service/v1/rules/xsrf-token

      (ii) If you defined destination as (b) then your service task URL will be:
      /rest/v1/rule- services/java/ShoppingCartPromotionRules/DiscountRuleservice

      and token URL will be: /v1/rules/xsrf-token

      Please note: the URL for token and invocation differs. See closely.

      (0) 
  3. Sruti Gupta

    Hi Archana,

     

    Thank you so much in taking all the time and explaining in detail.

    It’s my hard luck. I am again getting some error the log for which is inaccessible to me.

    I have done the setup as explained by you and those destinations(setup as per option b) work perfectly well when I consume the services in SAPUI5 application but something fails in workflow.

    I have ensured that relative paths are as per your suggestion, but some how they don’t work in workflow.

    Is there a way of checking the logs for the generated log id? It would be easier to debug.

    Regards,
    Sruti

    (0) 
    1. Archana Shukla Post author

      Hello Shruti,

      No its not possible to access the runtime logs. If you can setup a call then I can have a look at your implementation and suggest you better.

       

      (0) 
  4. Lucas Erni

    Hi Archana

    I have builded the workflow on my trial SCP there I can access the BRM without any problem.

    Then i copied the same program to my normal SCP and protected my workflow with an IDP, now it returns the error:

    The request to URL ‘https://bpmrulesruntimerules-”            “.hana.ondemand.com/rules-service/v1/rules/xsrf-token’ returned with a login request. Check the provided user credentials.
    Log ID: 9d5b3c01-b330-4013-bc6b-2********
    I checked my credentials a hunderd times and an if I use the url in GoogleChrome with the same credentials I can read the token.
    Do you know of any problem with using IDP, BRM and workflow together?
    As soon as i disable the BRM part of my workflow the process works fine.
    Kind regards,
    Lucas
    (0) 
    1. Archana Shukla Post author

      Hello Lucas,

      You need to enable BasicAuth in your IDP. By default the BasicAuth is not enabled in IDP. As mentioned in the blog, business rules call from workflow service-task need a destination that is configured with BasicAuth protocol.

      Regards,
      Archana

      (0) 
      1. Lucas Erni

        Hello Archana,

        I cannot find the correct setting, is it possible to send me a screenshot where to find it?

        I am using the SAP Cloud Platform Identity Authentication Administration Console.

        Thanks for your reply.

        Regards,

        Lucas

        (0) 
        1. Archana Shukla Post author

          Hello Lucas,

          You need to ask IDP provisioning team to enable BasicAuth in your IDP. Once enabled you will see HTTP Basic Authentication option configured as shown in the screenshot below

          (0) 

Leave a Reply