Skip to Content

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.


image

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.


image

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.

   FIELDSYMBOLS: <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 sysubrc = 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 syuname = ‘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.

image

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.

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Susan Keohan
    Hi R.J,
    Thanks so much for bringing this new functionality to light!  I am sure many SAP WF developers will be grateful to see your implementation.
    Yes, of course I am excited that SAP is showing SAP WF some love!
    Keep up the good work,
    Sue
    (0) 
  2. Sampath Adavelly
    Hi, Nice to know that SAP has released the new Editor functionality for BOR objects. Very well explained blog.

    The note number is 1639167. The link takes you to right number but number shows 1639197.

    (0) 
  3. Jocelyn Dart

    Hi R.J.,

    Could I encourage you to move this blog to the SAP Business Workflow space?  I’m a workflow regular and only stumbled across this by accident. I’m sure many other workflow folk would be interested to hear this news (and it will still be news to many of them).

    Regards,

    Jocelyn

    (0) 

Leave a Reply