Wednesday, April 24, 2013

Withdrawing SAP workflow tasks using paramaterized events

In one of the posts in 2011, I discussed using custom objects in SAP Workflow.

One of the things you can do with custom BOR objects, is add a custom event. The custom event can easily be raised using function SWE_EVENT_CREATE. You can use events to start workflows, but also to for instance influence an already running workflow on the specific instance of the object. You can implement the raising of an event using this function easily using for instance actions in transactions or using transaction events.

Let's look at an example.
If you would for instance create a workflow on an opportunity, which should start when the opportunity reaches a chance of succes > 80%, but the workflow task should be ended if the opportunity changes status 'lost' or 'won'.
In this case, you would create 2 custom events on the opportunity object:
  • Chance_of_success_changed with parameter
  • Status_changed
You could then create a workflow on the event chance_of_success_changed, and as a first step, check if the chance of success is > 80%, or create a startcondition on the workflow.

In order to be able to withdraw the workflow task when the status is changed to 'lost' or 'won', I would use the stop mechanism as explained here.

As the event is 'Status_changed', and we do not want to withdraw the workflow on all status changes, I would create a parameter on the event 'new_status'. We fill the workflow container before calling function SWE_EVENT_CREATE using 'swc_set_element' (from include <cntn01> ) lt_container new_status <value> and transfer the container as parameter 'event_container'.


In the parallel path for the stop mechanism, I implemented a while loop in which the workflow is listening to the event status_changed. The parameter new_status is bound to a parameter in the workflow container called 'status_from_event'. The while loop continues until the status_from_event equals 'won' or 'lost'. If this condition is met, the while will be ended and the parallel path will continue ending the outstanding workflow task.




No comments:

Post a Comment