Initiate your Workflow from SAP Cloud Platform Integration Services
You must have read the blogs on this much-awaited SAP Cloud Platform Workflow Service which has been a new addition to SAP Cloud Platform services.
Among various benefits that this service offers, this blog will cover one of the most requested aspect of how-to-start workflow service from SAP Cloud Platform Integration services. By doing so, we have expanded the use of workflow services such that it can be consumed for building extension scenarios like that of Employee Onboarding inSuccessFactors, Travel Expenses Approval in Concur solutions systems, to name few.
In this blog, you will learn how can you start a workflow using HTTP protocol from your cloud integration flow. In this example, I would be showing you how to start the workflow to onboard a newly hired employee of a company that is using SuccessFactors as their employee on-boarding tool. For sake of simplicity of understanding, I have used only those integration components that are required to start the workflow.
Please note that the workflow used in this example is already designed and deployed in the cloud and this blog will not cover modelling of the workflow.
Let us get started …
- Create an Integration Flow in SAP Cloud Integration in Web Application
https://uacp2.hana.ondemand.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/da53d93cd8fb47ff9ea55b6b278cd85e.html - Model the integration flow as shown in the screenshot
- Fill in the properties of various components of the integration flow as shown below.
- Sender Component: HTTPS
-
- Content Modifier
Workflow service requires XSRF token to be generated before the service call is made to create workflow instances. For this, you need a Content Modifier where you will define the headers to fetch the CSRF token
If you have specified any input payload for the workflow service, then you need to collect it for passing it later during starting the workflow service
-
- Next, you need to have a request-reply component and a Receiver component you have to make call to an external REST-based workflow service
- Request-Reply
- Receiver: HTTP protocol with following detail
- Address is the URL to fetch the XSRF token.
<workflow-service-URL>/workflow-service/rest/v1/xsrf-token - You can find more details from the official API documentation: https://help.sap.com/doc/wfs_api_documentation/Cloud/en-US/wfs-core-api-docu.html
- Workflow service APIs can be used only if the user has the desired roles. For more information on the Authentication and Roles refer the documentation: https://help.sap.com/viewer/f63bbdc234ce4211ab2cdb44564a0acd/Cloud/en-US/df943e71122448caaf3c49f5ffd80627.html
- You need to define the Credentials for basic authentication in SAP Cloud Platform Integration (from eclipse application) and use the same as “Credentials” property as shown above https://uacp2.hana.ondemand.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/6912d63bbbc64aee8bbd4ff10314c60c.html
- Next, you again put a Content Modifier to define the message header and property to create workflow instance by calling workflow REST-based API
Message Header and Body
To start workflow, the message body is mandatory and that too in a specific format.
Let us study from our example above. Here is the message body{ "definitionId": "idid01e867c5-a7a6-4f04-9380-1a5684a5ab85", "context": { ${property.requestPayload} } }
where
- definitionId is the ID of the workflow definition. You can get the same from the Workflow Monitor launch pad
- context is the input payload for the workflow. Note as we already saved the input payload in step b, we use the same here as ${property.<property-name>}
For more information on Monitor Workflow, refer the official documentation:
https://help.sap.com/viewer/f63bbdc234ce4211ab2cdb44564a0acd/Cloud/en-US/df943e71122448caaf3c49f5ffd80627.htmlFor more information on the service call, refer the API documentation:
https://help.sap.com/doc/wfs_api_documentation/Cloud/en-US/wfs-core-api-docu.html#
Workflow Instances –> /v1/workflow-instances –> POST - You finally need to have a mandatory script task that sets the cookies to the message header. You can paste the entire script as mentioned here.
import com.sap.gateway.ip.core.customdev.util.Message; import java.util.HashMap import java.util.ArrayList import java.util.Map import org.slf4j.Logger import org.slf4j.LoggerFactory import groovy.xml.* import java.io.*; def Message processData(Message message){ def headers = message.getHeaders(); def cookie = headers.get(“Set-Cookie”); StringBuffer bufferedCookie = new StringBuffer(); for(Object item : cookie){ bufferedCookie.append(item + “;”); } message.setHeader(“Cookie”, bufferedCookie.toString()); Logger log = LoggerFactory.getLogger(this.getClass()); log.error(“cookie”+ bufferedCookie); return message; }
- Finally, you have make a call to the workflow service to create the new instance. For that, you need to add following two components with respective details as shown below
- End Message
- Receiver: HTTP protocol with following details
Address is the URL to create the new instance.
<workflow-service-URL>/workflow-service/rest/v1/workflow-instances - You can find more details from the official API documentation: https://help.sap.com/doc/wfs_api_documentation/Cloud/en-US/wfs-core-api-docu.html
- Workflow service APIs can be used only if the user has the desired roles. For more information on the Authentication and Roles refer the documentation:
https://help.sap.com/viewer/f63bbdc234ce4211ab2cdb44564a0acd/Cloud/en-US/df943e71122448caaf3c49f5ffd80627.html - You need to define the Credentials for basic authentication in SAP Cloud Platform Integration (from eclipse application) and use the same as “Credentials” property as shown above.
https://uacp2.hana.ondemand.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/6912d63bbbc64aee8bbd4ff10314c60c.html
- Next, you need to have a request-reply component and a Receiver component you have to make call to an external REST-based workflow service
- Once you have modelled the integration flow, Save and Deploy the integration flow to the server
- Run the integration flow from POSTMAN or any REST-client of your choice. I will use POSTMAN here to show you the execution results
- In the POSTMAN, I have entered the URL for the Cloud Integration service as:
http://<CPI host>/http/start-workflow
where start-workflow is the sender connection address - As body, I have given the input payload that is needed by my workflow to consume
- As result, you will see that an instance is created with an id and other details
You can now go to the Workflow Monitor to see the instance
For more information on Monitor Workflow, refer the official documentation:
https://help.sap.com/viewer/f63bbdc234ce4211ab2cdb44564a0acd/Cloud/en-US/df943e71122448caaf3c49f5ffd80627.html
- In the POSTMAN, I have entered the URL for the Cloud Integration service as:
Wasn’t that simple? Indeed, it is. I have already used it in few extension scenarios for SAP applications and it works seamlessly. Additionally, you can add a timer in this integration flow to automatically start the workflow for any new requests is triggered in the backend system like new employee is onboarded in SuccessFactors or new expenses report created in Concur systems etc.
Use this service to play around for your requirements and share your findings. I will be all happy to help you with your queries, if any.
Very nice documents. Thanks.
I am using a trial account, I don't find the "Integration Flow in SAP Cloud Integration in Web application".
Hi Archana,
your code snippet has two little errors, in opposition to the screenshot:
br,
fabian
Thanks Fabian for the diligent check. Changes are done!
Hi Archana ,
The documentation links are broken. Could you please update that or share the correct links in the comment section?
Regards,
Rajesh
There was a change in API documentation link. Updated in the blog. Thanks!
Are these steps still needed? Including the groovy script?
This is more for Neo Workflow where XSRF token have to be preserved and based on session. For CF workflow, this is not needed.