Technical Articles
Embed Business Rules SAPUI5 control in your custom applications
Pattern 1 – In App Extensions for Cloud Applications
This is the second blog of my blog series on Business Rules Consumption Patterns. In previous blog on Usage Scenario#1 of Pattern 1, I explained how business rules can be used directly from your custom applications which is deployed on SAP Cloud Platform.
Usage Scenario #1
Embed Business Rules SAPUI5 control in your custom applications
Business Rules can be also managed by the applications build by customers & partners. It gives the flexibility to provide an custom interface to the business users to directly manage rules without exposing the technical aspects like data-types, rulesets, rule service etc.
This is achieved by embedding Rule Builder SAPUI5 control in your custom application. Rule Builder is available from version 1.40 in SAPUI5 control library.
- Follow Murali Shanmugham‘s excellent blog where he very nicely explains how to embed the rule-builder control in your application and then access it via Fiori Launchpad
Here are some important touch points in the SAPUI5 application (where you will embed the Rules Builder control) are:
- Coding your view.xml file to embed Rule Builder UI control of type Decision Table as shown:
<rules:RuleBuilder id="ruleBuilder" types="DecisionTable" editable="{path:'IsDraft', formatter: '.formatterIsDraft'}"/>
- Coding you Controller.js file to (a) initialize vocabulary, (b) configure and setup Rule Builder control, (c) implement actions for Activate, Edit, Deploy and Cancel buttons
You can know more in SAPUI5 samples to learn more on how to do that:
https://ui5.sap.com/#/entity/sap.rules.ui.RuleBuilder
- Deploying the application after you have embedded and coded the business rules control
- Accessing the application via the available application url. At a time, you can manage single rule via the rule builder control. The rules builder control needs information like rules project ID, rule ID, rules service ID and rule version, to be able to load the respective information.
Note: Currently only decision table based rules can be authored and managed using rule builder control. Soon, we will also release text-based rule builder control as well.
In this blog you learned about Consumption Pattern #2 where you saw how you can embed a decision table SAPUI5 control in your application. All you need to do is: (a) Insert the RuleBuilder control in your view.xml , (b) Implement the Controller.js to load the metadata of the rules via public APIs, (c) Code the button actions for Activate and Deploy (c) Finally, Deploy the application from SAP WebIDE and (d) Access the application to manage the business rules.
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 in your Neo environment.
- For cloud foundry, use this cf-rulesmanager.zip.
(Instructions are simple and available inREADME file)
Related Blogs
SAP Cloud Platform Business Rules – Extensions and Consumption Patterns
Use SAP Cloud Platform Business Rules in your custom applications
Using Business Rules in SAP Cloud Platform Workflow
Embed Business Rules in Cloud Foundry Application
Hi Archana,
Is there any other control available apart from Decision Table Editor?
Regards,
Pranjal
Hello Pranjal,
We will soon release Text Rule as well but for now only Decision Table control.
Is there anything else you looking for?
Hi Archana,
Thanks for the blog . I imported the project and tried with the steps and not able to get the projectId from jQuery.sap.getUriParameters().get("ProjectId") , I passed the project ID from the rule url as mentioned in the doc. But getting null , did I missed any thing ? Please help
Regards,
Srikanth.
Hello Srikanth,
As mentioned in the blog, you need to open the Business Rules editor and navigate to the project. On the URL you will find the project ID encapsulated under Project like
https://bpmruleseditor-myrial.dispatcher.hanatrial.ondemand.com/index.html#//Projects(2e6417e0f0c94ef28d99fc6d9681bc3e,000001)/ProjectDetails/view
Hi Archana,
Can we use output of one rule as input to another rule ?
Have you tried mapping a Decision tree to a decision table ? Or have you done any analysis on that?
Regards,
Pranjal
Hello Pranjal,
Yes, you can use output of one rule to invoke another rule - but you need to do that either via cloud integration or in your custom application. In future, when we have Flow Rules, then you can define the order of the execution of rules.
Can you elaborate more with example of what kind of mapping of Decision Tree to Decision Table you are referring to?
Hi Archana,
I see that a new version of the code has been uploaded on GitHub. I am unable to understand what is the change in the code for Edit.
I tried importing this piece of code in webIDE, and on running it I see that Rules are getting activated post deployment(can been seen in developer tools)
Regards,
Sruti
Hello Sruti,
Yes there is a very small change in the Edit press function where refresh is moved after the edit has happened. This is because of some recent developments in the control due to which in-place editing was not appearing when using my code snippet.
Hope that helps,
Archana
How to use the Value Help in RuleBuilder ui5 control?
Hello Sergio,
There is no difference on using value help from the tool or from UI5 control. Please read my blog on Value Help
Hello Archana, thank you for reply.
In Cloud Plataform Business Rules, I have the option for value help:
But in RuleBuilder control, no have:
Its any configuration? Can you help me?
Hello Sergio,
Yes there is a configuration needed when you load the decision table control. Please download the rulesmanager.zip mentioned above. You will note these 2 changes in the code. You can directly copy and paste them from the zip file
1. Expand call for Value help should include ValueSources
urlParameters: {
“$expand”: “DataObjects/Associations,DataObjects/Attributes,ValueSources”
}
2. Modification in the Initialization of Vocabulary Model to include setting of model to expression language after each setData() call.
oExpressionLanguage.setData(data);
oExpressionLanguage.setModel(that.oVocabularyModel);
Hi Archana,
The biggest functionality missing is to able to test for the end users.
We were thinking of building the test functionality for our customer and is there a way we can retrieve the data objects metadata dynamically as there is some dataobject id available. If yes what is the url?
Regards,
RL
Hi Archana,
I have worked extensively on SAP BRF+ and I was having a look at your posts. Very informative. Our entire Pricing logic runs on BRF+ where we take the output of one Rule and use it as an input to the other. I see you had mentioned about Flow rules in your previous posts. I did explore the Business rules in CF and found only Decision Table and Text rules. Do we know when Flow rules will be available ? And is there any roadmap to introduce more Expression Types like Table Operation, Loop, Formula, Procedural calls(In other terms – invoking On-prem GW services or something like this).
My biggest question is can we deploy this to our On-prem CRM system to be used internally for something else or in One order transactions ?
Regards,
Karthik
Hello Karthik,
Answers to your questions are as follows:
Thanks Archana.. I will get going with the answers provided.. I will get back to you if I am stuck somewhere. Thanks for your answers..
Hi Archana ,
I was trying to embed Business Rules in ui5 app . But the destinations for runtime and repository are not created automatically . Can you provide the destination config. Unable to load the app since metadata fails to load This is in Cloud Foundry
Thanks
Namrata
Hello Namrata,
At the end of the blog, I have provided the sample for cf-rulesmanager, please refer that. You do not need any destination in CF and can work with the service key for business rules instance.
Hi Archana Thanks for your response
As indicated in the below post I have followed all the steps . The service is deployed and tested on API hub . :
https://blogs.sap.com/2019/04/13/embed-business-rules-in-cloud-foundry-application/
How ever when i try to run the app :
bpmrulesrepository/rules-service/rest/v1/projects I get a 404 for this url and projects are unable to load
Can you please help with this
Thanks
Namrata
Have you created a business rules instance, and referenced it with the UI project?
Yes Archana , It is referenced .
Hello Archana ,
We are using SAP business Rule service as in SAP BTP to meet our client requirements. I would like to know if we have any satandard interface which allows only managing the decissions. After we ran the workflow booster we do see the below applications in Html5 applications.
but apart from rule editor applcation the other two application related to sapruledecisionviewer and saprulemanagedecision does not work.
Thanks
Prerna