Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Archana
Product and Topic Expert
Product and Topic Expert
7,423
SAP Cloud Platform together with Cloud Foundry is offering the flexible cloud native enterprise platform to build, deploy and manage applications. SAP is key member and contributor in Cloud Foundry community. There have been great advantages of Cloud Foundry in SAP’s platform-as-a-service strategy, due to which SAP Cloud Platform services in Neo environment have already started being provisioned in Cloud Foundry. Business rules is one of them

SAP Cloud Platform Business Rules Service in now available in Cloud Foundry Trial and Enterprise environment – for both platform-as-a-service (PaaS) and software-as-a-service (SaaS) engagement model. It has been released currently for CF/AWS and Microsoft Azure environments. know more details on the data centres from here

I have put together this quick guide series that introduces you to the business rules service in Cloud Foundry where I have divided the learnings into 2 parts:

  • In first part, you will learn how to subscribe to business rules application, use rules editor to model, manage and deploy rules and execute/test business rules service in Cloud Foundry

  • In the second part, you will learn on how to consume the service from custom application deployed in Cloud Foundry.


In this first blog, I will concentrate on how you can use business rules application in Cloud Foundry in just four steps: (a) Configure Business Rules Entitlement, (b) User Role Assignment, (c) Accessing Business Rules Editor application to model rules and (d) Creating service instance and service keys to execute the business rules
>>>>>>> we also have SAP Tutorial on Getting Started. Try it out!  >>>>>>

 

I. Configure Business Rules Entitlement



  1. Login to SAP Cloud Platform trial


https://account.hanatrial.ondemand.com/cockpit#/home/trialhome


[Note: If you are not a registered user then first sign-up for the trial account and then login with the set username and password.]



 

  1. Click on Enter Your trial Account to create (if you are login for the first time) and open the trial account. Cloud Foundry is a limited period trial for first 90 days and then you can choose to extend it for another 30 days. You can choose the data center US or Europe to create the trial account

  2. You will see that a global account and subaccount is already created for you with name <your-user-name>trial and trial respectively, as shown. Click on Go to Space


As a concept in Cloud Foundry accounts management, Global account represents the scope of the functionality and operations you are exposed to. A global account can have one or more sub-accounts that allows you model, deploy and manage your services and applications. For more information, you can read here



 

  1. Click on the trial sub-account tile to navigate into the account. It is from this sub-account that we are going to check entitlements and configure business rules service.


In the Overview page you will see all the quota assigned for various services and memory allocations for applications in your trial account. This quota or resource allocation defines which and to-what-extend you can use specified set of resources.



 

  1. Click the Entitlements, to see if you have the needed Business Rules entitlement. In trial account, the entitlements will automatically be there, but in your other accounts it might not be there, in that case follow this guide to assign the entitlement. Also note, the Plan of the entitlement - for trial it will be lite and otherwise it will be standard plan for business rules


 

II. Access Business Rules Editor Application via HTML Application Repository (new & recommended)


Before I start this section, I would like to highlight certain things about business rules editor. To those who are aware of business rules editor in Neo environment – there is absolutely no change. Infact, the editor in Neo and Cloud Foundry is EXACTLY the same. No learning experience required.

For those who have not seen/used business rules editor before, follow the blogs to know how-to model, manage and deploy rules. This section would not cover modelling of the rules. I would recommend you to go-through the blogs to familiarize yourself with modelling notations and operations for business rules.

Assuming that you know how-to work with business rules editor, let us understand how to get access to the editor. This can be done in two ways (a) via HTML Application Repository - which is the newer way to get access to the business rules application and (b) via Subscription - which is the old way of enabling the subscription (as in section III below).

>>>>> Subscription is no more supported now >>>>>>>

In this section, we talk about how to enable the business rules editor via HTML Application Repository. There are 2 ways how you can achieve this (a) one is using the command-line tool and (b) other is using the SAP WebIDE. In this blog, I will show using the command-line tool (which is always my personal preference) but you can replicate the same using SAP WebIDE. Both are the pretty simple and straight forward to perform.

  1. Create the folder structure as shown in your eclipse environment (or anywhere in your local file system)



 

  1. Copy and paste the code mentioned in this documentation (step 2, 3 and 4) for package.json, xs-app.json and mta.yaml respectively.



 

  1. Execute the following commands one-after-another to create the MTAR file. This MTAR file will be deployed in the CF environment to create required approuter and service instance to access business rules editornote: Open the command-line tool and ensure that you are in businessrules_editor/approuter folder and then run these commands
    npm config set @sap:registry https://npm.sap.com
    npm install


    ⇒ Once you complete the installation, you will notice the node_modules folder created inside your businessrules_editor/approuter folder


  2. Navigate to the parent folder but before you run the nest set of commands ensure that you have download the mta jar file from cloud tools under section Multi-Target Application Archive Builder
    cd ..
    java -jar <path to mta jar downloaded from cloud tools> --build-target=CF build





    ⇒ Once the command is successfully completed, you will see a businessrules_editor.mtar generated in your folder as shown in the screenshot



     

  3. Now we need to deploy the generated MTAR file into the cf environment. For that you need to login the to CF using the following commands and enter the username, password of the account and org where you want to deploy the application
    cf api <api-endpoint>
    cf login




⇒ before you deploy you need to ensure that you have the right set of commands installed. For this you run the command cf help and you must see deploy command listed as shown:



⇒ If you do not see this listed, then you need download and install CF MTA Plugin from cloud tools



(goto the readme text of the highlighted link and install the plugins are mentioned there)


⇒ Once you are ready, run the deploy cf command in command-line



cf deploy <location of the generated mtar file>


If you go to the Applications of your space (where you have deployed the MTAR), you will see bpmruleconsumerapprouter created and started



you can also click the application link to see the Service Bindings



 

III. Create Business Rules Service Instance


In the previous sections, you learnt how you can create business rules service instance in Cloud Foundry and access the rules editor to model, manage and deploy rules. In this section, you will learn about the service broker of business rules - which will be used to create service instance and execute rules in the platform. I will also show you how you can test your rules from any available rest client using service keys of a service instance.

  1. Open your Sub Account in Cloud Foundry trial and go to Entitlements and check if you can see Business Rules service already added. In trial account, the entitlements will automatically be there, but in your other accounts it might not be there, in that case follow this guide to assign the entitlement. Also note, the Plan of the entitlement - for trial it will be lite and otherwise it will be standard plan for business rules



 

  1. While working on trial, a dev space would already have been created for you. Go into the dev space to create service instance and bindings





  1. Open Business Rules service from Service Marketplace and create a new instance with name of your choice. For more information on services in Cloud Foundry, read here



While creating the service instance keep all the options as they appear by default and give the Instance Name of your choice.





  1. Now lets us create service keys that will generate credentials which will be used to communicate with the service instance. To do so, navigate into the service instance you have created above





  1. Switch to Service Keys and create a new service key with name of your choice



Here you have to note down certain values because we use them while testing our business rules from rest client and also when you want to consume this service from your custom application:




  • clientid: used as username for any grant-type option

  • clientsecret: used as password for any grant-type option

  • url: used to generate the authorization token to access APIs

  • runtime_url: host url to execute the rules runtime APIs

  • repository_url: host url to execute rules design time APIs


 

V. Configure Trust and Assign Authorizations


Now you have to assign roles (to your user) associated with the service instance of this business rules service broker. You can either create a new role collection or update the existing one.

  1. Open your trial subaccount and go to Members. Check if your username is already added. As this is a trial account, you should be already a member, by-default.





  1. To assign business rules roles, first you need to create the role collection. For that, open Security --> Role Collection and add a new role collection with name of your choice let’s say “Business Rules”. If you already have a role collection where you want to add business rules roles, then you don’t need to create a new collection.





  1. Go into the role collection to add 2 roles (RuleRepositorySuperUser and RuleRuntimeSuperUser of bpmrulebroker) to the collection. These roles are required to access the business rules editor to model, manage and deploy rules.






  1. Open Security --> Trust Configuration to assign the role collection to your IDP service (which is SAP IDP is case of trial)



Enter your user id or email address to see what role collections are assigned to you. To assign the newly created role collection to your user, use Add Assignment option. If you already have a role collection where you just want to assign role associated with business rules, then you do not need do this step.




VI. Access Business Rules Editor Application (new & recommended)



  1. Bind the service instance and application by

    • going into the space and open Services --> Service Instances 

    • select the service instance for business-rules service as shown

    • Click on the "link" icon





  1. In the pop-up, select the bpmruleconsumerapprouter application to bind this application with the approuter and Save the configuration.

  2. Due to new bindings, the given application need to be restarted. Go into the Applications and select the bpmruleconsumerapprouter application.

    • From Overview section and click on the Restart button.

    • Wait for the application to the restart




Now, click on the link under Application Routes (as highlighted in green in above image) - and this is the business rules editor available for you to model and manage rules in CF environment

So, now you have setup to the business rules application, assigned all desired roles to your user and opened the editor for modelling.

You can choose to model your own rules or as a sample you can import Shopping Cart Promotion Rules from GitHub. If you opt for latter, then after you have imported the rules, you need to activate the artefacts (in this given order: Data Objects, Rule Services, Rules and Rulesets) and deploy the rule services. As you deploy the rule service, a REST service is created which can be accessed via business rules runtime public APIs.

VII. Test Business Rules


As final step, let us now test the rule service from any rest-client. I will use Postman here, but you can use any available client you have.

>>>> You can also test from API Business Hub. Follow this tutorial >>>>

 

  • Open Postman and enter following details according to your trial.

    As an example, I am executing the sample Shopping Cart Promotion Rules that I referred in the previous section. If you have your own rules, then you need to change the URL and body accordingly.


Method: POST


URL: https://bpmruleruntime.cfapps.eu10.hana.ondemand.com/rules-service/rest/v1/rule-services/java/Shoppi...


where https://bpmruleruntime.cfapps.eu10.hana.ondemand.com is the runtime_url from service key


     Authorization
Select TYPE as OAuth 2.0 and then click Get New Access Token and enter these details       and then click Request Token. Once you get the token click Use Token.


      (a)  Grant Type as Client Credentials
(b)  Access Token URL, Client ID and Client Secret which you can get from service key (as explained in step 13 above)


           



Headers
Content-Type: application/json
Authorization: Bearer <access_token> (this will already be filled after requesting token)


Body


[


{


"__type__":"Product",


"Category":"Flat Screen TVs",


"Quantity":11,


"Soldby": "Very Best Screens"


},


{


"__type__":"Seller",


"Name": "Very Best Screens"


}


]




when you execute the business rules, you can see the discount output from the rules in the response body as shown. [Note: I am also showing you the snippets of the decision table rule so that you can understand the response we got after execution of the business rules]




 

You can also run repository APIs (in similar fashion) to model and manage the business rules (in case you do not want to use the editor and work on purely PaaS model). In the above example, I showed you how to authenticate business rules runtime APIs with password-grant type, but you can also use other grant-types to call the service.

This concludes the first part of the blog where I focussed mainly on business rules setup and using the manage rules application to model, manage, deploy and invoke rules. I will soon publish the second part of the blog, until then try and use the business rules service in Cloud Foundry and connect back to me if you have any queries or feedback.

♦ Second part of the blog is published now!
37 Comments
raeijpe
Contributor
0 Kudos
Thanks for sharing, Gives good insights what is possible.
b_deterd2
Active Contributor
0 Kudos
When I open the application I get the No Authorization. I assigned all the rules roles to myself.
Archana
Product and Topic Expert
Product and Topic Expert
Hello Bert,

Open the application in incognito mode. Browser caches the login information, if you have logged in earlier with your user when it did not had the required roles.

Regards,
Archana

 
former_member208449
Active Participant
0 Kudos
Hi Archana/Bert,

I too face the same issue. Even when I use incognito it doesn't work.
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello G B,
Close all the browsers and then open in incognito mode. Try also clearing the cache. If you have opened two incognito window then also it won't work. Also double check if the role assignment is correct.

 
sankar_bhatta
Participant
0 Kudos
HI,

 

Need your help. I am trying to deploy a business rule service from hana trail account and I am getting below error. could you please give me an hint on what could be wrong here.

former_member208449
Active Participant
0 Kudos
Hi

Now I get an error during rule service deployment - unknown error. Contact technical support.

Please help.

 
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello GB,
there might be something missing in your project. Open Developer Console in your browser, navigate to Networks tab and deploy again. You can check the service response as reason for failure. Rules messages will be improved in upcoming releases
former_member201760
Participant
0 Kudos
sankar_bhatta check if in your expression in the rule you have left any cells empty
sankar_bhatta
Participant
0 Kudos
Yes that was the issue. Archana helped me to solve the issue
0 Kudos
Hi archana.shukla ,

I am using a trial account. When I try to subscribe to business rules from the cockpit, the subscription shows as "processing" for  some time and then again comes back to "not subscribed". Because of which I am not able to navigate to the rules application.

Any help would be appreciated.

Thanks
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello Nandan,
We are looking into the issue and will keep you posted.

 
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
This should have been resolved. Please let me know if you still face the issue
ImranMohammed
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Archana,

I dont see Business rule service under Marketplace in CF. I tried both in trail and also Canary account. Even Entitlement is not showing Business rule service. Any idea why its not showing up?
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello Imran,
You will not see business rules service in Service marketplace if you have not entitled for business rules (lite plan) in CF trial. Canary is strictly for internal purpose. we have a different process for it. Please send separate email to me and I can guide you accordingly.

Regards,
Archana

 
ImranMohammed
Product and Topic Expert
Product and Topic Expert
0 Kudos
Thanks Archana for your prompt reply. Will get in touch with you.
0 Kudos
Hi archana.shukla ,

The Issue still persists.
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Please raise an issue in component: LOD-BPM-RUL and provide your account details. Ops team will fix it.
former_member429595
Discoverer
0 Kudos
Hello Archana,

Could you share the pricing model for productive usage?

Thanks.
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Business Rules is available with SCP Workflow Service. You can find the pricing information here:
https://cloudplatform.sap.com/capabilities/product-info.SAP-Cloud-Platform-Workflow.df696e5a-d973-4e...

Regards,
Archana
former_member429595
Discoverer
0 Kudos
Thanks, Archana.

This is user based metering per month. In our case, we are considering using rules as a 'reuse' scenario. There may be only one user setting up the rule definition, but thousands of API calls to execute the rule - using a technical user.

For this scenario, is there metering/pricing based on number of calls (or maybe resources consumed)?

Regards.

 
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Please send email for the request.
former_member66030
Discoverer
0 Kudos
Hi Archana,

Appreciate if you could help me here in regards to Business Rules in Neo environment.

 

I have configured by following the documentation however I am getting the following error message not sure how to resolve this though.

 

"Entitlement is missing. Assign entitlement to access Business Rules editor by following the procedureSAP Cloud Platform Business Rules Documentation"

 

I exactly followed the same step for trial account for HANA, it works. The entitlement issue we are getting this is in our customer subaccount.

We are using SAP ECC on Hana DB. We are still not on S/4

 

Appreciate your assistance.

 

Sathya

 
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello Sathya,
This is known issue. Can you please raise a CSS ticket on LOD-BPM-RUL and business rules Operations team will help you with the entitlements. Mention your account details in the ticket.

Regards,
Archana
former_member66030
Discoverer
Hi Archana,

Thanks for your response. Yes I did what you said and they have assigned the entitlements to our tenant which is working now 🙂

Thanks once again!

Sathya
0 Kudos
Hi

Where do i request access for Service: Business Rules - on Neo Foundry? i am unable to Manage Rules Project see the error below

Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello,

Please add RuleRepositorySuperUser role to your user in cloud foundry (read documentation if needed). Then open the link in incognito mode.
anuptiwari
Explorer
0 Kudos
Hello Archana,

 

I am getting invalid token error on requesting token. Can you please help
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
You don't need XSRF token for business rules in CF. You can use the service key credential to invoke business rules with OAuth protocol
anuptiwari
Explorer
0 Kudos

I am getting status 401Unauthorized error on POST call while testing from POSTMAN

Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
What are you tying to do, invoke business rules API ? then can you be sure that you calling right API. Send me the API URL and the and the other details that you entering in POSTMAN
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
The URL is wrong. I do not know where you got this issue from :

https://<host>/rules-service/rest/v2/rule-services
anuptiwari
Explorer
0 Kudos
Thanks this helped.  I am able to fetch the token.

But my post call is giving 404 error.


Postman



Token


Can i send screenshot over mail of the issue in case this is not clear.

Rule Name - Discount_rules

Rule service - Discount_ruleservice

 

Thanks for your quick response
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
Follow this API documentation to invoke the rule:

https://api.sap.com/api/SAP_CF_BusinessRules_Runtime_V2/resource

  • The URL is wrong

  • the body is not correct

anuptiwari
Explorer
0 Kudos
Thanks Archana, it is working now. Your help is highly appreciated. You Rock !!!

Can you help me with some blog which i can refer for invoking the business rules from ABAP code..

Thanks again 🙂
Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos
You can take hints from these blogs. Though they are calling workflow service instead of business rules service but you can surely get idea how to do it

https://blogs.sap.com/2018/12/04/hunting-zombies-the-scp-way/

https://blogs.sap.com/2019/08/28/example-for-a-s4hana-cloud-mte-extension-using-in-app-badi-ems-with...