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: 
Dan_Wroblewski
Developer Advocate
Developer Advocate
In the last week, archana.shukla and chaitanyapriya.puvvada wrote very comprehensive blogs (Start Process from SAP Build Apps using APIs and Integrate SAP Build Apps and SAP Build Process Automation using SAP BTP Destinations) on creating triggers in SAP Build Process Automation so you can trigger your process via API, for example, from SAP Build Apps.

Both take advantage of new functionality in both products, especially the ability to define API triggers and the use of destinations inside SAP Build Apps to make REST calls (and not just OData calls).

Now I just want to make a small addition to the blogs, to show how you can call other SAP Build Process Automation APIs to find out the status of your process instance.






Both what Archana and Priya described and what I describe here were part of the demo we created at SAP TechEd keynote with juergen.mueller last month. You can learn how the demo was created in my blog post on the SAP Builders group (which I urge you to join).

Process Instances


First, you have to remember that each time you trigger a process, you are creating a new process instance. And you can track that instance via additional SAP Build Process Automation APIs.

When you trigger a process,, the API returns a bunch of metadata, including the ID of the process (screenshot from Archana's blog).


Above is what is returned when you successfully trigger a workflow. Most important is the id parameter, which you need in subsequent calls.

When I triggered a workflow, I saved this idin a variable, so I could use later. The schema for triggering the API is made up of request parameters, and there is no place to define the response schema as far as I know. You probably could just add the response schema to the request schema, but this seemed messy to me.


Instead, I just used formulas to access the response data.
outputs["Create record"].response.id


Getting Info About Your Process Instances


In my SAP TechEd demo, I wanted to find out if the process was approved. Unfortunately, there isn't a lot of ways to know this (just whether the entire process completed or not), so I created 2 dummy mail processes, and depending on which was executed in my process I could tell if the process was approved.


So now I set up the API call.

I created a new BTP REST data resource, using the same destination as the one for triggering workflows (my destination had a path of /workflow/rest/v1/workflow-instances). The base URL contained just a parameter for the process instance id, which I called spainputid.


And the create action used the following formula for the path, since I wanted to get the execution log, the same execution log you can see in the Monitoring tab within SAP Process Automation:
"/" +  query.record.spaidinput + "/execution-logs"


So now to get the information, all I have to do is execute a Create record flow function against this data resource, and supply the id in my parameter.


The response includes all the steps that were executed, partially like this:
[
{
"id": "708",
"type": "WORKFLOW_STARTED",
"timestamp": "2022-11-15T14:06:34.871Z",
"referenceInstanceId": "b6b4a7b6-64ee-11ed-9879-eeee0a8b7afc",
"userId": "sb-clone-41c25609-33a1-4c44-97d8-34fcd2316008!b3591|workflow!b116"
},
{
"id": "709",
"type": "EXCLUSIVE_GATEWAY_REACHED",
"timestamp": "2022-11-15T14:06:35.037Z",
"referenceInstanceId": "f9ef0828-bbe1-4185-a87a-a9f50961f731",
"activityId": "condition_1",
"subject": "Condition"
},
{
"id": "710",
"type": "MAILTASK_CREATED",
"timestamp": "2022-11-15T14:06:35.123Z",
"referenceInstanceId": "114187f5-4016-4f9d-b346-5fdc8bc5c834",
"activityId": "mail_2",
"subject": "Alert Daniel - Needs Approval"
},

...

]

I put the response in a page variable (simply defined as a list of objects), and then I used a formula to see if the Approved Mail step had been executed.
NOT(IS_EMPTY(FIND(pageVars.Workflow, item.subject == "Approved Mail")))

You can view what other SAP Build Process Automation APIs you can call in the SAP API Business Business Hub, for example to get the context. The link takes you directly to the automation section of the documentation.

Pretty cool, I think. Let me know if you have any questions.




See all my daniel.wroblewski#content:blogposts and connect with me on Twitter / LinkedIn