SAP Build Process Automation – how to trigger process(es) from an automation


Let’s imagine a typical use case – your automation should fetch multiple invoice files from some source (file folder, Outlook, Gmail, FTP, etc.). Automation will loop through your file collection, extract data from those invoices using DOX and then analyze if everything is OK. Automation can post some of the invoices but what if PO is missing, or your 3-factor authentication found problems, or confidence level of recognition is low for some elements, or for larger total amount you must have a multi step approval?

There can be many different workflows that you will need to fire based on different conditions found in your invoices.

This blog post will show you how to do that – call SAP Build Process Automation [SBPA] Business Process  (workflow artifact) from an Automation (RPA artifact).


Figure 1: Process example (click to enlarge)

This was just one use case example but there are many situations and more complex scenarios where you will need to automate something and based on detected conditions trigger a different workflow for each condition.

Figure 2: Automation example (click to enlarge)

Assumption is that all your processes are created and deployed in SAP Build Process Automation and each process is triggered by API call. (To find out how to create a process workflow with API trigger check this blog.)

Figure 3: Process’ API trigger example (click to enlarge)


In most cases your workflow will be part of the same project as your automation, but please note that you can call any SBPA workflow that is part of another project or even deployed on another tenant (as long as you have needed security credentials).



In monitoring part of the SBPA check details of your deployed process API. It’s important to know the expected JSON payload structure for this particular process (red rectangle). It’s important to know exact field names as well as type of values (in this example 2 string inputs, one numeric and one boolean). On this screen you will find URL and definitionID values that we will need later (yellow rectangle).

In your project create a new custom data type called “Context”. It’s important that names and types are exactly the same as in your API definition.


Now create an additional  custom data type called “WF API Trigger” that will hold all necessary (project/tenant specific) data to execute an API call.


Define 2 new variables in your automaton project. First is of type “WF API Trigger” and rename output to myAPI.

For input values select custom data and add needed values. Before you saw where to find values for api_url and definition_id. To find other values you will need to go to your BTP Cockpit and click on service key of your SBPA instance and copy values from pop-up window:

Values for client_id, client_secret and token_url can be found here:

Please note that url from service key MUST be appended with “/oauth/token” so the value of token_url should look like this ““.

Now add any values you want for Context variable and rename it to myContext:

Before calling the web service, you must prepare the JSON object with all the necessary data. There is a package in the Store called “Web services Best Practices”. I encourage you to check those examples (as well as other packages from the store because they are great for learning and inspiration).

However, examples in this package don’t cover cases where you need to authenticate using oAuth 2 (we first need to fetch the token and then execute POST call with payload)  so you will now add custom script to your project and define 2 inputs (myAPI of custom data type WF API Trigger and myContext of type Any) and output named options of type Any.

Click on “edit script” to add code and define inputs and output.

Copy-paste this code:

async function fetchToken() {
    const data_cred="client_id="+myAPI.oAuth.client_id+
    const options = {          
        method: 'POST',
        url: myAPI.oAuth.token_url,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
    try {
        const response = await;
        const token = JSON.parse(response);
        var at=token.access_token;
        return at;   
    } catch (error) {

let token = await fetchToken();

// ------------------------------

let input = {

let auth = "Bearer " + token;

let output = {
    method: 'POST',
    url: myAPI.api_url,
    headers: {
      'Content-Type': 'application/json',
    responseType: 'json', // parse the body of the result to get a JSON object
    resolveBodyOnly: true, // get only the body of the response
    json: input

return output;

Now you just need to add the standard action “Call Web Service” and use the output JSON object from the Custom Script as the input for this step. Also define name for output object (in this example “api_output”):

Optionally add “Log message” action to show JSON object api_output in console and execute your automation.

Upon successful execution you can find that JSON response object contains (among other data) ID of your started process:


If you go to the monitoring section of SAP Build Process Automation you can find that your process is running:


Next steps

In my next blog post I will show you how you can easily turn this into generic solution that you can just add in all of your projects where you need to call workflow API from an automation.

To stay current will all the new and exciting things related to SBPA please check:

Enjoy building with SAP Build. 🙂

Original Article:

Related blogs


Please enter your comment!
Please enter your name here