Overview
This blog post will cover the step-by-step process for setting up SAP Cloud Platform (SCP) Business Rules in the Cloud Foundry (CF) environment using SAP Business Application Studio (BAS).
In this sample scenario, I will be creating an application using BAS that will allow users to access the Business Rules service in the CF environment and let consuming applications (such as a REST client) call the Business Rules REST API to invoke the rules.
At a high-level, the following topics will be covered:
- Enable SCP Business Rules service and BAS in the SCP Cloud Foundry environment
- Create Role Collections and assign to the user
- Create a Business Rules service instance and service key
- Create a project in BAS and configure Business Rules
- Create a sample Business Rules project
- Test the service with Postman
Prerequisites:
- You are a global administrator in your SCP global account (required for subscriptions)
- You are an org and space member (required for configuring entitlements and creating service instances)
- You are a security administrator (required for role assignments/creation)
NOTE: I am using a production account in the Australia, Sydney (ap10) region.
1. Enable SCP Business Rules service and BAS in the SCP Cloud Foundry environment
Configure Entitlement for the Business Rules Service
- Navigate to the organization > Entitlements > Configure Entitlements > Add Service Plan
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in1-1024x380.png?resize=730%2C271&ssl=1)
- Select Business Rules Service and select a service plan (basic) > Add and Save
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in2.png?resize=730%2C456&ssl=1)
Subscribe to Business Application Studio
- Subscriptions > SAP Business Application Studio > Subscribe
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in3.png?resize=730%2C314&ssl=1)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in4.png?resize=730%2C423&ssl=1)
2. Create Role Collections and assign to the User
Assign the relevant BAS Developer Role Collection
- Security > Role Collections > Business_Application_Studio_Developer
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in5.png?resize=730%2C291&ssl=1)
- Edit > Add User (enter ID based on configured IdP. eg: email if using the default SAP ID service) > Save
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in6-1024x277.png?resize=730%2C197&ssl=1)
Assign relevant Business Rules Roles/Role Collection
We need to add roles with the following application identifier: bpmrulebroker*.
There are two roles with such application identifier: RuleRepositorySuperUser and RuleRuntimeSuperUser.
There are two ways to assign these roles to your user:
1. If your account has a subscription to the Workflow Management service, these role collections will be automatically created. Assign your user to one of these role collections (if applicable):
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in7.png?resize=445%2C111&ssl=1)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in8-1024x289.png?resize=730%2C206&ssl=1)
2. Else, create a custom role collection and add the required roles (RuleRepositorySuperUser and RuleRuntimeSuperUser)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in9.png?resize=730%2C271&ssl=1)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in10.png?resize=730%2C329&ssl=1)
3. Create a Business Rules Service Instance and Service Key
Create a Business Rules Service instance
- Go to your space > Services > Service Instances > Create Instance
Service: Business Rules
Service Plan: basic
Instance Name: <any name>, in my case: businessrules
Leave Parameters blank (step 2), and ‘Create Instance’
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in11.png?resize=596%2C552&ssl=1)
Create a service key for the created service instance
This service key will be used later to call the business rules API
- Open the created service instance > Service keys (Create) > Enter a Service Key Name > Create
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in12.png?resize=480%2C520&ssl=1)
- Open the created service key and copy the credentials in a separate file for now. We will use these credentials when testing the Business Rules service in Step 6.
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in13.png?resize=572%2C279&ssl=1)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in14.png?resize=594%2C384&ssl=1)
4. Create a project in BAS and configure Business Rules
- Go to subscriptions > Business Application Studio > Go to Application
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2023/09/Create-a-project-in-BAS-and-configure-Business-Rules.png?resize=730%2C314&ssl=1)
Create a new Fiori workspace
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in16-1024x531.png?resize=730%2C379&ssl=1)
Create a project from a template
I will be using a standalone SAP Fiori Free Style Project to generate the boilerplate code for the application.
The most important configuration objects are the approuter (xs-app.json) and the mta.yaml. We will remove modules that are not required for this demo.
NOTE: This step can be done in a different way (eg: manual creation of objects from a basic MTA project template).
- In your empty workspace > Create new project from a template
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in17.png?resize=730%2C259&ssl=1)
- Select SAP Fiori Freestyle Project
Target Environment: Cloud Foundry
Template: SAPUI5 Application
Project Name: <any>, rulesmanager in my case
HTML5 application runtime: Standalone Approuter
HTML5 module name: <any>
Do you want to add authentication: Yes
Enter a namespace: <any valid namespace>
Enable Karma Test: No
View Name: <any>
Add data service: No
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in18.png?resize=730%2C642&ssl=1)
Configure the Business Rules service in the application
- After the project is created, open the mta.yaml file.
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in19.png?resize=272%2C265&ssl=1)
- Remove unrequired modules and resources (highlighted in yellow). You can also delete the generated HTML5 folder in the project
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in20.png?resize=492%2C817&ssl=1)
- Add the created Business Rules Service instance (businessrules, Step 3) as a required resource
My mta.yaml file:
_schema-version: "3.2"
ID: rulesmanager
version: 0.0.1
modules:
- name: rulesmanager-approuter
type: approuter.nodejs
path: rulesmanager-approuter
requires:
- name: rulesmanager_html_repo_runtime
- name: uaa_rulesmanager
- name: businessrules
parameters:
disk-quota: 256M
memory: 256M
resources:
- name: rulesmanager_html_repo_runtime
type: org.cloudfoundry.managed-service
parameters:
service: html5-apps-repo
service-plan: app-runtime
- name: uaa_rulesmanager
type: com.sap.xs.uaa
parameters:
path: ./xs-security.json
service: xsuaa
service-name: rulesmanager-xsuaa-service
service-plan: application
- name: businessrules
type: org.cloudfoundry.existing-service
build-parameters:
before-all:
- builder: custom
commands:
- npm install
- Enter this configuration to the xs-app.json, of the approuter.
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in21.png?resize=730%2C275&ssl=1)
{
"welcomeFile": "comsapbpmrule.ruleeditor/index.html",
"authenticationMethod": "route",
"routes": [
]
}
Build and Deploy the Application
- Right click on the mta.yaml file > Build MTA
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in22.png?resize=520%2C344&ssl=1)
- Set the correct target CF space. To set the the correct space, run cf login in the BAS terminal or use the highlighted shortcut below.
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in23.png?resize=379%2C522&ssl=1)
- Once the build is complete and the correct target has been set, open the mta_archives folder and deploy the generated MTAR archive to the CF space.
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in24.png?resize=635%2C252&ssl=1)
After deployment, check Applications in the space and open the newly created application.
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in25.png?resize=508%2C212&ssl=1)
You should be able to see the Business Rules landing page.
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in26-1024x259.png?resize=730%2C185&ssl=1)
5. Create a sample Business Rules project
Next, we will create sample Business Rules project. This is not the focus of the blog so I will just provide a summary of the steps required and some screenshots for reference.
The service we will be creating will read a User’s organization and return the Approver details based on the decision table.
Procedure:
- Create a project
- Create data objects (ie. define input/output structure)
- Create a rules service (which reference the data objects)
- Create rules/decision tables
- Create rulesets (and assign rules)
Create data objects (ie. define input/output structure)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in27-1024x581.png?resize=730%2C414&ssl=1)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in28-1024x555.png?resize=730%2C396&ssl=1)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in30-1024x452.png?resize=730%2C322&ssl=1)
NOTE: after creation each object must be Validated and Activated (ie: Status = Active).
Create a rules service (which assign the data objects as Input or Result)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in31-1024x534.png?resize=730%2C381&ssl=1)
Create rules/decision tables
eg: if organization of the User is C then the approver group is SCPGroupC and the approver name is ApproverC
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in32-1024x665.png?resize=730%2C474&ssl=1)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in33-1024x671.png?resize=730%2C478&ssl=1)
Create rulesets (and assign rules and rule service)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in34-1024x604.png?resize=730%2C431&ssl=1)
After creating and activating all the entities, Activate the whole project.
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in35.png?resize=730%2C183&ssl=1)
6. Test the service with Postman
Once the Business Rules project is activated, we can test the rules service using a REST client such as Postman.
To do this, we will need the service key credentials which we created in Step 3.
NOTE: any value enclosed in <> should be taken in the service key credentials.
Operation: POST
URL: <rule_runtime_url>/rules-service/rest/v2/workingset-rule-services
Authorization
Type: OAuth 2.0
Token Name: any
Grant Type: Client Credentials
Access Token URL: <url>/oauth/token
Client ID: <clientid>
Client Secret: <clientsecret>
Client Authentication: Send as Basic Auth header
Get a new Access Token and use it
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in36-1024x378.png?resize=730%2C269&ssl=1)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in37.png?resize=589%2C403&ssl=1)
Body
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in38.png?resize=709%2C263&ssl=1)
{
"RuleServiceId": "5641e858cf2341e6b380849d47aed340",
"Vocabulary": [
{
"User": {
"organization" : "C"
}
}
]
}
where
- “User” and “organization” is the Input structure and attribute respectively.
- RuleServiceId: ID of the rule service. (Add the ID to the visible columns as this is not visible by default)
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in39.png?resize=730%2C194&ssl=1)
Result:
As you can see, when we pass a User with ‘C’ as organization, we get the expected Approver per the decision table.
Hooray!
![](https://i0.wp.com/www.erpqna.com/wp-content/uploads/2021/02/in40.png?resize=439%2C277&ssl=1)