Embed Business Rules in Cloud Foundry Application
SAP Cloud Platform Business Rules was released for enterprise consumption in Cloud Foundry environment last month (help portal). In my previous blogs, I have explained how to subscribe to the business rules in CF (blog1) and also to consume the service from custom application (blog2). In this blog I will address how-to embed business rules or rule builder control in an application.
Most of the coding to embed the business rules SAPUI5 control in CF application is same as described in my previous blog but there are some fundamental and configurational changes that are needed due to the multi-target application development.
please note: This is not a step-to-step guide instead it would just address the additional things you need to successfully enable decision-table or text control in your CF application.
- Create MTA-project (you can do that from WebIDE in neo environment)
(developing MTA applications)
- Create HTML5 Module
- Code the application to embed business rules
(see the blog)(help on developing HTML5 module)
- In the yaml file you need to configure the app-router, the xsuaa binded to the app-router and the business-rules service instance as shown:
… and the same you need to provide as resources in yaml file. Depending upon whether the resource already exists or had be created you define the type as org.cloudfoundry.existing-service or org.cloudfoundry.managed-service respectively.
- Finally, you need to add the routes in the approuter depending upon which business rules APIs (authoring or runtime) you want to call. (know more about syntax)
- Build the mta application.
note: If you are using WebIDE, then before building the application ensure that you have configured your CF account in WebIDE or else you can use CF commands to build your application as well.
note: after you have successfully build the project, you will find the deployable mtar file in mta_archives of your project.
- Right click on the mtar and Deploy the application to SAP Cloud Platform via Deploy –> Deploy to SAP Cloud Platform option
- Once the application is successfully deployed, you can find the URL from the SAP CF cockpit from the space <where the application is deployed> –> Applications
- The final URL will be:
For Example: https://rulesmanager-approuter.cfapps.sap.hana.ondemand.com/sapdemorulescustom/index.html
That’s it. It is pretty simple and straight. You can also use this to migrate your Neo application embedding rules editor to CF application. All the steps mentioned above are not specific to business rules, it applies to any CF application calling service APIs.
Sample Reference Application
I have shared a rulesmanager.zip project in GitHub which you can use to learn and reference on how-to embed the business rules in your application. All you need to do is import this application, modify yaml file based on your CF setup, build and then deploy the mtar file.
I have created a Business rules project in SAP cloud and activated it.
I am trying to test the API, first by calling the XSRF API using postman. I am getting 404 not found error.
I then checked the destination in the connectivity section for bpmrulesruntime to see if the connection is up,I'm getting following message:
Can you guide me in testing the ruleset that I have created in the project using postman.
The URL used for API is incorrect. Here is the correct one:
Also note these v1 APIs and are deprecated now. Use the v2 APIs
Thank you for the quick reply.
I used V1 API for now, but getting following response:
However, the project Test1 and Rule Service RSV_001 exist:
Also, could you check the passing of parameters in body is correct.
the input structure IM_CARR_CONN contains two elements CARR and CONN of type string.
the result structure EX_FLTID has element FLTID
The rule service was not deployed. Now it is deployed, and I am getting a 200 Response but no response body:
How to invoke the rule service so that it returns the correct result?
Also, is there no way to test this directly from the cloud platform UI.
This is because nothing is matching. Also "__type__" in body is to be your data object name
What is the URL for v2? I tried different variations, but it does not work.
If you switch Details tab of the API in API Business Hub, you will see the production URL which tell you the URL to be needed. Here are some examples:
Body should be like (you can get the information if you see the Body description of the API in API Business Hub)
"Category": "Flat Screen TVs",
"Soldby": "Very Best Screens"
"Name": "Very Best Screens"
Could you please provide certain insights about achieving the same as a local development approach. Means without deploying the code into BTP.
I was trying with default-env.json and tried to place it under rulesmanager_appRouter folder and pasted the VCAP service details from environment variable. But this gets stuck with Auth error.
So do you have any project (Github) to refer which talks about local development and testing locally rather deploying each time to cloud.
Thanks in advance!