Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Recently after a campaign from the workflow user groups of ASUG and VNSG SAP has released new enhancements for SAP Business Workflow. The most prominent enhancement is that SAP has finally enabled the current version of the ABAP editor when editing a BOR object in SWO1 (see note 1639167 for details). There are however a number of other improvements that can also be useful to a workflow developer and to promote these I have decided to showcase one: dynamic decision options in user decisions (see note 1648822).

Setup

To showcase this functionality I have created a simple workflow model with a single user decision step.


At design time the user decision has 3 decision options: Approve, Reject and Terminate process. Without the enhancement this step would always show these options and to for hide one of the options we would need to model a condition in the workflow and add a second branch with a second user decision with just the two remaining options. With the enhancement we can however implement a workflow exit based on interface IF_SWF_IFS_DECISION_EXIT that allows us to change the decision options at runtime, which is then included on the program exits tab of the step definition in the workflow model.


Enhancement

My example implementation of the exit does two things.

  • Based on the container element AMOUNT in the workflow container the description of the approve option is changed to reflect who the next approver in the workflow will be. For the showcase this is hard coded, but since in a real life situation you can obviously add your own code to determine the approver based on the workflow context.
  • The option to terminate the process is removed based on the current user. Since the work item exit is called when the end user opens the work item, we know who the current user is and can for instance look at the authorization of the user. For the showcase the username of the current user is compared to a hard coded value (=my userid).

The ABAP code of the method is shown below.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

METHOD if_swf_ifs_workitem_exit~event_raised.

   DATA: lt_decialts  TYPE swrtdecialts,

         lo_container TYPE REF TO if_swf_ifs_parameter_container,

         lv_amount    TYPE wrbtr.

   FIELD-SYMBOLS: <decialt> TYPE swr_decialts.

   IF im_event_name = if_swf_ifs_decision_exit~c_evttyp_before_decision.

*   Get the workflow container from the workitem context (use get_wi_container to get the workitem container).

     lo_container = im_workitem_context->get_wf_container( ).

*   We need the value of the AMOUNT container element.

     lo_container->get( EXPORTING name = 'AMOUNT'

                        IMPORTING value = lv_amount ).

*   Get the decision alternatives from the container as defined in the workflow builder.

     CALL METHOD im_workitem_context->get_decision_alts

       IMPORTING

         et_decialts = lt_decialts.

*   1. Change the decision text to reflect the next approver based in the AMOUNT.

     READ TABLE lt_decialts ASSIGNING <decialt>

     WITH KEY altkey = '0001'.

     IF sy-subrc = 0.

       IF lv_amount <= 500.

         <decialt>-alttext = 'Approve (the next approver is Mark)'.

       ELSE.

         <decialt>-alttext = 'Approve (the next approver is Ann)'.

       ENDIF.

     ENDIF.

*   2. Remove the 3rd option when based on the current user.

     IF sy-uname = 'LOOY'.

       DELETE lt_decialts WHERE altkey = '0003'.

     ENDIF.

*   Set the new alternatives values to the workitem context.

     CALL METHOD im_workitem_context->set_decision_alts

       EXPORTING

         it_decialts = lt_decialts.

   ENDIF.

ENDMETHOD.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Result

The result of this is that if I execute the user decision workflow task and the container element AMOUNT has been set to 600, I will see the following screen.

Note that the option to terminate the process is not present and the description of the approve option has been changed to reflect the next approver.

Conclusion

Changing the decision options at runtime can be a very useful. It removes the need for modeling additional branches in the workflow when you want to hide decision options for certain users or based on some other business logic. By changing the decision texts on a case by case basis the decision making process can be more streamlined for the end user, since the decision options can convey more specific information about the consequence of the option.

7 Comments