The easy way to edit workflow context variables
TLDR: SAP Workflow Management doesn’t provide an app to edit workflow context variables, even though this is very useful when resolving issues. I built my own Fiori app. Perhaps this functionality could be provided as standard in future?
One of my customers uses SAP Workflow Management (running on SAP Business Technology Platform) extensively for a side-by-side extension app. The process begins when the requestor completes the ‘Project Creation’ form in a custom UI5 app. Upon approval of the form a number of business partners and commercial projects are created in S/4HANA.
A custom workflow handles the approval process and another handles the creation of master data after approval. Occasionally workflow instances are halted by errors. Once we establish how the error has occurred we make changes to the UI5 app or the CAP (Cloud Application Programming Model) Java app to make sure that same error can’t happen again in future.
Many errors come from user input, such as adding spaces in the wrong places in a tax code. In this case we would improve the validation and formatting in the form to prevent a recurrence, and/or we might change the Java app to handle input in different formats.
The problem is that these changes may be too late for the workflow instance that is now stuck in error.
Often in the workflow we use a script task to prepare data in a context variable ready for it to be passed in an API call. The service task that follows makes the API call. For example, we might collate the business partner information (including some reads, in our case, of custom business objects in S/4) ahead of the call to create a new partner in S/4HANA.
If these data are erroneous (e.g. we have a space in the wrong place) then when we retry the workflow instance the API will fail once more. What we need in this scenario is to make an edit to the workflow context, so that when we retry the workflow it can progress to completion.
The Monitor Workflow Instances app doesn’t provide for a context edit, so I decided to build my own Fiori app using SAP UI5. The purpose of this blog post is to share this concept, at least in its current MVP (minimum viable product) form. The app uses the RESTful API that is provided with the SAP Workflow Management service (for the Neo & Cloud Foundry environments). We were already using this service to create new instances of our workflows from the UI5 app.
The app uses the Flexible Column Layout control. First we choose the workflow instance we want to edit:
The workflow context is rendered in tree form, which can be expanded as required:
We then select the context node that we want to edit:
Note that the save button is enabled when you change the value in the text area.
Of course we need to keep security in mind, as it wouldn’t do to allow the editing of workflow context variables without controls. First, we should only allow limited access to this app. Second, we should only assign the standard role WorkflowContextAdmin in production when strictly required and most likely only temporarily. This should be the case even if there is no such user-friendly UI5 app deployed. NB the workflow log does show who edited the context, but it doesn’t show details of the edits.
Another point to note is that the standard API is not an OData service. In my UI5 app I used AJAX to make the API calls. The API allows us to query instances, query the context and update the context.
It would be great to hear your comments if you know of a way to edit the context using the standard apps, or if you have developed an app yourself. Don’t you think this would be an excellent feature to add to the standard SAP Workflow Management suite of apps?
For more background and references see my earlier blog series on SAP Workflow Management