cancel
Showing results for 
Search instead for 
Did you mean: 

SAP BTP CAP - How to trigger or cancel workflow from Node JS?

chphaniv
Explorer
0 Kudos

Hi All,

We are implementing a CAP project, where we are triggering workflow and cancelling workflows from frontend UI. Following this approach we are facing few issues related to security. I believe we can do the same from backend CAP actions. Would appreciate if you can share details or code snippets on how to achieve this. Thanks...

Regards,

Phani.

View Entire Topic
Willem_Pardaens
Product and Topic Expert
Product and Topic Expert

Hi Phani,

You can interact with SAP Build Process Automation like any other external service in CAP.

You will need:

  • A service instance of the "process automation service" in the "standard" plan, and create a Service Key
  • A destination pointing to this service instance and using the key details as OAuth2ClientCredentials
  • Consuming this destination in CAP:

package.json:

"dependencies": {
  "@sap-cloud-sdk/http-client": "^2.9.0"
},
"cds": {
"requires": {
"spa_api": {
"kind": "rest",
"credentials":{
"destination": "YourDestinationName"
}
}
}
}

service.js:

srv.on('YourAction', async (req) => {
const workflowContent = {
"definitionId": "eu10.abc.xyz",
"context": {
"param1": null,
"param2": null
}
};
const SPA_API = await cds.connect.to('spa_api');
const result = await SPA_API.send('POST', '/workflow/rest/v1/workflow-instances', JSON.stringify(workflowContent), { "Content-Type": "application/json" });
return result;
});

Using the SAP Build Process Automation REST APIs you can trigger any action on the workflow you want.

darsh2269
Explorer

Thanks willem.pardaens

your answer help me to configure destination for rest kind destination in CAP.