Skip to Content
Technical Articles

SAP Workflow Management and SAP Business ByDesign Events

This main focus of this article will be to show how to use SAP Business ByDesign Events to trigger an SAP Workflow using the SAP Business Technology Platform Workflow Management. You will remember the SAP Business ByDesign Events blog posts which outlined different methods for capturing SAP ByDesign events … “How to get SAP Business ByDesign events in a loosely coupled solution” series. Here we will show how to utilize one of these examples, specifically the “Bridging the event pub/sub for SAP Business ByDesign with an internal push approach“. While this article shows this one example, you can use any of the methods outlined in the SAP Business ByDesign Events blog posts.

I do not re-cover the setup of the SAP ByDesign Event setup in this article.  Please review the “Bridging the event pub/sub for SAP Business ByDesign with an internal push approach” for initial setup. Here we will cover the needed changes to allow an event, such as Invoice creation in SAP Business ByDesign will trigger a simple SAP Workflow via SAP Workflow Management.The example that we will show is an email being sent to a specified email address based on the Invoice event from SAP Business ByDesign.

Technical Details about ByDEventBridge Architecture and Design

To get started …

Please review:

  1. SAP Business Technology Platform (BTP) trial account
  2. Set Up Workflow Management in Cloud Cockpit
  3. Get Started with SAP Cloud Platform Workflow
  4. Access to the Bridging the event pub/sub for SAP Business ByDesign with an internal push approach SAP Cloud Application Studio source code.  You can access it from the linked article.

Overview

The image below shows a simple SAP Workflow that is built to accept information from SAP Business ByDesign via HTTP and then send an email to a specified email address containing the SAP Business ByDesign Invoice number and date of creation

 

 

SAP Business Technology Platform SAP Workflow changes

You will need to update your workflow_instance (wm_workflow) with the JSON below to enable the REST API, otherwise, you will not be able to trigger our workflow instance with an HTTP call
{
    "authorities": [
        "WORKFLOW_INSTANCE_GET",
        "WORKFLOW_INSTANCE_START",
        "MESSAGE_SEND",
        "TASK_GET",
        "TASK_COMPLETE", 
        "TASK_UPDATE",
        "TASK_GET_CONTEXT",
        "WORKFLOW_DEFINITION_GET",
        "WORKFLOW_DEFINITION_UNDEPLOY"
    ]
}
As a result of the update, you should have a Service Key that contains the following information which will be used to set the Event Publication Channel of SAP workflow in the ByDEventBridge CAS code
For the email component of SAP Workflow, we also need to configure a Destination as part of the Connectivity within the SAP Business Technology Platform
In this example we have setup a email account and the associated properties that sends the email to the email address(s) as defined in the SAP Workflow “ByDMailWF”

SAP Business ByDesign Changes

In the workflow image above you can see under the General tab the workflow ID “ByDMailWF”.  This will be used in the ByDEventBridge code to understand that once an event is triggered, in our example by saving the invoice in the SAP Business ByDesign interface, which workflow is to be called.

To allow this SAP Business ByDesign event to trigger a workflow, we first need to have an Event Publication Channel defined in the Business Object Event Bridge as shown

If we open the 05-SAP_WORKFLOW channel, we can see the definition

You can review the “Bridging the event pub/sub for SAP Business ByDesign with an internal push approach” blog and associated sample code for how to create Event Publication Channels.  What is important here is:

Channel ID: user defined

Channel Type of SAP Workflow from the drop-down: 7 – SAP Workflow

Access Service Name: SAP_WF_Access

This information comes from the CAS code as shown and as you can see points to the SAP Workflow API

 

Communication Scenario for Channel Access: SAP_WF_AccessCS –  is part of the CAS sample code and Communication Arraignment, Communication System pointing to the Hostname Workflow API URL.

Authentication Method: OAuth 2.0

User and Password: comes from the Service Key that you setup when you create these for the Workflow Instance “wm_workflow” that is created when you add SAP Workflow as a service to your BTP Account.  As part of the Service Key you create when you view the contents of the key, you will see as part of the JSON the “clientid”: and “clientsecret”:.  For more information on setting up SAP Workflow Management please see Set Up Workflow Management in Cloud Cockpit.

Also you will need to edit the ByDEventBridge CAS code Event >BusinessObjectEvent.bo > Publication.node > Action-Publish.absl for the pair.Value = “xxx_asset_assignment” where the pair.Value = “ByDMailWF” which is the name of our workflow as this defines what workflow to call when our Invoice event is triggered

SAP Workflow

We saw in the beginning of the article the overall SAP Workflow to take the Invoice event from SAP Business ByDesign and when the Invoice is Saved, trigger the workflow via an HTTP call.  You can see for the “MailTask2” task in the SAP Business Application Studio, that I have hard coded an email recipient in the “To:” field.  We could have also used the the email from the SAP Business ByDesign data being sent from the ByDEventBridge code if in that data we had included the email used on the Invoice in SAP Business ByDesign using ${context.CustomerEmail} as an example

We also use HTML for the body of the email with the “bydesign_wf_mail.html”. Here you can see we are using the ${context.ObjectID} and ${context.CreationDate} to get from the data sent from SAP Business ByDesign the Invoice and created date information and add to our email

<!doctype html>
<html>    
     <head>        
	     <title>Workflow Service Email Notification</title>        
		 <style>            
		     h3 {
			 font-family: serif;            
			 }            
			 p, dl, dd, dt {                
			     font-family: sans-serif;            
				 }
				 dt {                
				     text-indent: 5em;
					 }        
		 </style>
	 </head>    
	 <body>        
		 <h3>Notification from SAP ByDesign that your invoice has been completed</h3>        
         <p>Invoice ${context.ObjectID}</p>
         <p>Date ${context.CreationDate}</p>        
		 <p>The SAP ByDesign workflow that you triggered has been successfully completed.</p>        
		 <p>Sincerely yours,</p>        
		 <p>SAP Workflow service</p>    
	 </body>
</html>

Lastly we show that when we create an Invoice in SAP Business ByDesign

We can then check in the SAP Workflow Monitor > Workflow Instances to see our SAP Business ByDesign Invoice has triggered our workflow

and then we can finally see that the workflow has created the email to the specified email account that contains the Invoice ObjectID and CreationDate

Conclusion

Hopefully you have been able to see how we have been easily able to capture an SAP Business ByDesign Event by SAP Workflow and then, in this example, trigger an email. While this is a simple example, the uses of SAP Workflow as part of the SAP Business Technology Platform are only limited to the imagination of the developer. As stated above, we used just one example of capturing an SAP Business ByDesign Event with SAP Workflow Management but we could have used any of the SAP Business ByDesign Event options as described in the blog series “How to get SAP Business ByDesign events in a loosely coupled solution“.

 

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