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: 
svenhuberti
Product and Topic Expert
Product and Topic Expert
1,947

Introduction

2024-02-01_10-00-50.jpg
Did you know we take around 35.000 decisions everyday?

"What do I wear? What do I eat? Shall I go to the gym?"

And we do not take decisions on a random basis: we need input and context:

"What's the weather? What did I eat yesterday? Is that shoulder still hurting?"

This decision-taking-spree also applies to the business world: business rules can help to simplify implementation and maintenance of simple to complex decisions - in business processes, integration flows or applications.

Goal

The goal of this blog is to guide you through the creation of a SAP BTP Business Process Automation business rule as well as explaining how to call that business rule through an API Call.

Prerequisites

In order to follow the steps hereunder, I recommend that you have:

  • basic knowledge of SAP BTP concepts,
  • access to the SAP BTP cockpit to create service keys,
  • access to the SAP Build Process Automation service,
  • any tool to call APIs (I recommend Postman).

Implementation

Create a decision in SAP Build Process Automation

Open your SAP Build Process Automation environment and click on "Build an Automated Process".

2024-01-16_14-40-32.png

Select "Business Process".

2024-01-16_14-40-57.png

Give your project and name and click "Create".

2024-01-16_14-41-33.png

Hit the "Cancel" button when asked to create a process.

2024-01-16_14-41-51.png

On the canvas of your project, select "Create/Decision". 

2024-01-16_14-42-05.png

Give it a name that will fit to your project.

2024-01-16_14-42-59.png

The decision is now created and we need to configure it. To do so, we start with the Input and Output parameters. Click on "Add input parameters".

2024-01-16_14-43-32.png

In our case, we use an example of associating a support group to a ticket, based on the ticket type and ticket urgency. Hence we need "TicketType" and "TicketUrgency" as input parameters (as strings) and "SupportGroup" as output parameter.

2024-01-16_14-44-40.png

Once in- and output are defined, we can add a rule to our decision. Click the second step of the decision graphic and click on "AddRule" on the right. 

2024-01-16_14-45-24.png

As we keep things simple, we will use a "decision table". Enter the name and description as fitting your project, and click "Next Step".

2024-01-16_14-46-57.png

It's now time to define the actual conditions of the rule. Select the input parameters you just defined and define their label (friendly name) and set the operator to "equal" ("="). Once done, click on "Next step".

2024-01-16_14-47-37.png

Same as you did for the conditions, select "SupportGroup" to be a result a click on "Next step".

2024-01-16_14-48-13.png

Once you have reviewed the conditions, click on "Create".

2024-01-16_14-48-30.png

Now that you have defined input, output and conditions, you can define the actual content of the rule.

In the decision table on the right, enter the actual data of your business rule as depicted below. Once you are done, click on "Save".

2024-01-16_14-50-16.png

Now click on "Release".

2024-01-16_14-50-58.png

2024-01-16_14-51-28.png

Once a rule is released, it can be deployed. To do so, click on the "Deploy" button at the top right of your screen.

2024-01-16_14-51-44.png

The business rule is now available for use. Before you move to another screen, it is important that you save the ID of the business rule somewhere: it will be used later in our API call to uniquely identify the decision. 

Click on the "..." button at the top right corner of the screen and copy the "Id" information.

2024-01-16_14-53-00.png

Configure service key

Almost every service in SAP BTP can be access through APIs. To allow that access however, you need to define a service key.

If you haven't done it yet, create an instance of the SAP Build Process Automation. To do so, navigate to the "Instances and subscriptions" section of your subaccount and click on "Create". Select the SAP Build Process Automation service, pick the right plan and give it a meaningful name.

2024-01-16_15-00-25.png

Click on "Next" and "Create".

Now locate that service instance you have just created (or that was already there) and click on it. On the right side of the screen, you can see the service keys - if any. If you need one, click on "Create".

2024-01-16_15-03-21.png

This process is self-explanatory, simply give the key a meaningful name and click "Create".

Once created, you can see all it's details that you need for an API Call.

2024-01-16_15-04-54.png

It is a good idea to download or copy the service key now, so you can use it later.

Making the API Call

Now that you have created a business rule, written down its Id and created a service key to access it, let's move to the API call.

Authorization

I recommend to use the useful authorization feature on the folders or collection level so you do not need to reconfigure authorization for every SAP Build Process Automation business rule API call.

Open your API client - in our case Postman - and configure the authorization as follows:

  • "OAuth 2.0" , sent as "Request Headers"
  • "Token Name" can be chosen freely
  • "Client Credentials" is the grant type
  • "Access Token URL" is taken from the service key. It is the "url" property in the "uaa" section.
    Suffix that URL with "oauth/token" so that it reads something like this: https://yourSubAccountName.authentication.eu10.hana.ondemand.com/oauth/token
  • "ClientId" and "ClientSecret" are taken from the service key too. They are the "clientid" and "clientsecret" properties in the "uaa" section. 

2024-01-16_15-07-39.png

API Call

As per the documentation available on the SAP Business Accelerator Hub, decisions can be called through the POST method, passing the input as raw body.

Also in the documentation, you can find the endpoint of the API for your environment.

2024-02-01_09-09-46.jpg

In Postman, create a new request in your collection or folder on which you previously defined the Authorization.

The API Call should be configured as follows:

  • Authorization is "inherited from parent".
  • Method is "POST".
  • The "URL" is the "Production URL" you found in the SAP Business Accelerator Hub.
    You can also take it from your service key ("endpoints"."api") but make sure to suffix it with "/public/rule/runtime/rest".
  • The "Body" is sent as "raw". It contains the Id of the decision you have previously created, as well as the input parameters you have defined. It should look like this:

 

 

{
    "RuleServiceId": "fc3dde4285db06a702f3ed748006434e",
    "Vocabulary": [
        {
            "TicketUrgency": "High",
            "TicketType": "HR"
        }
    ]
}

 

 

This is what the request eventually looks like.

2024-01-16_15-09-08.png

Conclusion  

Thanks to SAP Build Process Automation, not only can you build human-centric processes, but you can also create centralized, re-usable and openly available decisions. 

2 Comments