Skip to Content
Technical Articles

Challenge Submission – Triggering sequential SAP S/4HANA process bots using API trigger in SAP Intelligent RPA

This is a submission for the SAP Intelligent RPA Tutorial Challenge.

In this technical blog post you will get an idea on how to sequentially trigger process bots. Let us see how SAP Intelligent RPA API trigger event can be used to handle the output of one process bot to trigger another bot. Following are the seven steps to perform the sequential bot trigger:

Step – 1. Create a project (ProcessBot 1) and export it to factory: 

    • Create a Project using Desktop studio and deploy it in cloud factory. In this case the bot may need to send data to a scenario via an API trigger or a Scheduled trigger. For this purpose you need to enter into the Properties window the inputs/outputs (Input to receive data and Output to send data).
      Add the items in the context window and click on Properties window to add the context variables in the Input Data Manager as shown in the below screenshot:

       

  • Login to SAP Intelligent RPA Cloud Factory and Navigate to Projects tab. Click on New Project and provide the project name and description.
  • Import the Desktop Package, then click on the package created. You can see the details of inputs and outputs (I/O)

Step – 2. Add the API trigger configuration:

  • On the Deployments tab, click Add trigger on the right of the deployment. Select API and Enter a name, description, priority and click create.
  • Once an API trigger is created, you can see the information you need to call the trigger. (Trigger URL, irpa-trigger-token, payload)
  • If you click on show required field only, we can see the actual payload needed to trigger the bot
  • For more information please follow Execute a Trigger of Type API
  • You will get the below values:
    • Trigger URL of ProcessBot 1
    • irpa-trigger-token
    • Payload sample

Step – 3. Generate the service key to access the API of ProcessBot 1:

  • Follow Create a Service Key to generate the service key.
  • Note: If SAP Intelligent Robotic Process Automation Service is not available in the service marketplace then we must enable it using SAP CP control center.
  • You will get the below values
    • Authentication URL: The Authentication URL is found under uaa, property url, in the service key
    • ClientID: it is found under uaa, property clientid in the service key
    • Client secret : it is found under uaa, property clientsecret in the service key

Step – 4. Create another project (ProcessBot 2) which will trigger the ProcessBot 1:

  • At first fetch the Bearer token using the Authentication URL, clientid, clientsecret from step 3 and Payload sample from step 2.
    ctx.ajax.call( {
    method: 'POST',
    url: <Authentication URL(The Authentication URL is found under uaa, property url, in the service key)>/oauth/token?grant_type=client_credentials",
    data:ctx.json.stringify(<payload from step 2>),
    contentType: e.ajax.content.json,
    headers: {'Authorization': 'Basic ' + ctx.base64.encode(<clientid> + ':' + <clientsecret> )},
    async: false,
    success: function (res, status, xhr) {
    var Bearertoken = ctx.json.parse(xhr.responseText).access_token;
    sc.endStep();
    return;
    },
    error: function (res, status, xhr) {
    ctx.log('error get')
    sc.endStep();
    }
    });
  • Make an API call to trigger ProcessBot 1 using Trigger URL, irpa-trigger-token and Payload sample from step 2 and Bearer token from above step
    ctx.ajax.call( {
    method: 'POST',
    url: "<Trigger URL of Bot1>",
    data:ctx.json.stringify(payload from step 2),
    contentType: e.ajax.content.json,
    headers: {
    'Authorization': "Bearer " + <Bearertoken fetched in step 4.a>,
    'irpa-trigger-token':"<irpa-trigger-token from step 2>"
    },
    async: false,
    success: function (res, status, xhr) {
    var runId = ctx.json.parse(xhr.responseText).runUid;
    ctx.log("runUid is: "+runId);
    },
    error: function (res, status, xhr) {
    response = res;
    if(res.status===403){
    ctx.log("API Trigger failed since "+ ctx.json.parse(res.responseText).message);
    }
    else{
    ctx.log("API Trigger failed with status: " + res.status);
    }
    }
    });​

Step – 5. Import Process Bot 2 in Cloud Factory and schedule it in unattended mode

Step – 6. Process Bot 2 will run successfully and trigger Process Bot 1

Step – 7. Job scheduling mode and Track the Execution:

  • Follow the below steps as shown below
    • On Execution of Process Bot 2, a job has been scheduled as a result of the request
    • Go to Monitoring tab and click on Agents
    • Search for your agent and check the mode of it
    • If the agent is in unattended mode, the job will start the execution
    • If the agent is in attended mode, the job will get executed and the bot will be in ready state
    • Change the mode of the agent to Background Unattended and now the bot will start the execution

These steps will help you to trigger process bots with the help of a process bot.

Try this out, let me know in the comments if you face any challenges.

Happy to help !!!

Be the first to leave a comment
You must be Logged on to comment or reply to a post.