Intercepting a forwarded work item
SAPblog
Intercepting a Forwarded Work Item
One of the frequent items I am asked to do as an SAP Workflow consultant is to permit the end user to select an approver for their item (PR, PO, Travel Request, etc.). I’m not a fan of this for several reasons. The worst-case scenario is that it allows for fraud (sending items that should be approved by high ranks to lower ranking personnel), and the best-case scenario is that it bypasses all the hard work we’ve put into determining who should get the item in the first place.
To resolve the issue, I have often allowed the end user to send to whomever they choose, with the condition that the system verifies the recipient as the item is forwarded. To do this, we require the use of a program exit in the SAP Workflow template step. This exit will verify that the recipient chosen by the end user is appropriate to perform the action requested. To implement a program exit, we require an ABAP class to be configured for this use and implemented in the SAP Workflow template step.
To configure the ABAP class, we create a new class in transaction code SE24 following all necessary conventions for the client, and we implement the IF_SWF_IFS_WORKITEM_EXIT interface.
This provides us a spot to implement our business logic, in the interface method IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED.
This method will be called several times during the execution of the work item, so we have to ensure our business logic is only called when the work item is being forwarded. Here is the sample code that I start with in these cases.
METHOD if_swf_ifs_workitem_exit~event_raised.
DATA: action TYPE string,
lv_userid TYPE xubname,
lt_rule TYPE STANDARD TABLE OF swhactor.
* determine what the end user is doing.
action = im_workitem_context->get_action_name( ).
* only execute the check if the user is forwarding an item
IF action = ‘SAP_WAPI_FORWARD_WORKITEM’.
* obtain the username that the end user has chosen.
TRY.
CALL METHOD im_workitem_context->get_action_data( EXPORTING im_parameter_name = ‘USERID’ IMPORTING ex_data = lv_userid ).
CATCH cx_wapi_parameter_not_found.
ENDTRY.
* verify the new recipient …
” insert code here…
ENDIF.
ENDMETHOD.
In terms of access, keep in mind that the code you implement here will be executed under the username of the person who is forwarding the work item. If they don’t have access to view the HR Organisational Structure for instance, you’ll have to find a workaround for that.
To implement the logic for any specific SAP Workflow template step, all that is required is to navigate to the step and enter the class name in the Program Exits tab for that step.
Once this is done, you can put a breakpoint in your code, and test the workflow.
I am a strong believer that there is always more than one way to solve a problem, so if you have any suggestions or alternatives, please feel free to submit them as comments below!