Further important BAdIs:
- Besides the update BAdI there are some more available to configure and control the Workitem processing in MyInbox:
- BAdI for Actions and Displayed Information: WF_TASK_SUPPORT (since ECC).
- BAdI for Attachments: WF_ATTACHMENT_PROVIDER (since 1809).
- BAdI for Comments: WF_COMMENT_PROVIDER (availability of BAdI comment attachments ABAP Platform Cloud 2102).
- BAdI to filter forwarding in MyInbox: WF_WI_FORWARD (new one available ABAP Platform Cloud 2105 SWF_WI_FORWARD_AGENTS_GET).
See also the course appendix with a summary of BAdIs or this blog.
To Implement the BAdI for Task Outcomes
To handle a decision that is made on the task we need to configure and implement a BAdI that will contain the logic for doing this. The BAdI class needs to contain the same logic for completing the task that is used in the assigned BOR object dialog method. These dialog methods are all slightly different, so you need to take it on a case-by-case basis when implementing the decision BAdI. Understanding how the step works in the workflow and how the dialog method is implemented is key in this process.
To implement the BAdI for Task Outcomes:
Create the BAdI configuration and class for decision handling. To do so, follow steps a through u.
Remain in the back-end ZME system, enter transaction /NSE18, and press Enter on your keyboard.
The enhancement spot for getting business context data is /IWWRK/ES_WF_WI_BEFORE_UPD_IB. Enter that into the Enhancement Spot field then choose the Display button:

You should now see the following:

Expand the BAdI definition so you see the following:

Right-click the Implementations node and choose Create BAdI Implementation in the context menu.

In the dialog box, choose the Create icon in the bottom right-hand corner.

In the Create Enhancement Implementation window, enter the details as shown below (replace 00 with your number) and choose the green check mark.

If you receive the Create Object Directory Entry dialog box, enter $TMP as the package and choose the Save button.

You will be brought back to the Select or Create Enhancement Implementation dialog box. Make sure your newly created enhancement implementation is selected as shown below and choose the green check mark.

The Create BAdI Implementation dialog box is displayed. Enter the details as shown below, and choose the green check mark.
Possible Entries in the Create BAdI Implementation dialog box
Field Value BAdI Implementation Z_BADI_ABSENCE_FORM Description Z BADI Implementation Absence Form Implementing Class Z_IC_ABSENCE_FORM 
In the Create Object Directory Entry dialog box, choose the Save button.

You should now see the following:

Enter change mode by choosing the Display/Change button.

Expand the BAdI implementation you just created and double-click Filter Val..

On the right-hand side, you will see the filter details view displayed. Choose the Create Filter Combination button (if it is not enabled, choose the Display/Change button again).

In the dialog box, select both WORKFLOW_ID and STEP_ID by holding down the Shift button on your keyboard and choosing the gray box next to each. Then choose the green check box.

You should now see the following:

Double-click in the Value 1 column of the STEP_ID row. You should see the following dialog box:

Enter 48 in the Value 1 field (48 is the step ID for Approve absence notification) and set Comparator 1 to "=". The filter should now look as follows:

Choose Continue (the green check mark).
Now set the WORKFLOW_ID filter by double-clicking the Value 1 setting and entering a value of WSXXXXXXXX (where the Xs are replaced with your assigned number) and set Comparator 1 to =.
Choose Continue (the green check mark).Your filters should now be set as shown below:

Activate your BAdI by choosing the Activate button.

In the Inactive Objects for FIORI window, choose the green check mark.

Note
You might see a warning telling you that the method that holds the actual implementation code has not been implemented. This will be done in the following section.Congratulations. You have created a BAdI that can be called to access the business context data of the absence approval notification step.
Implement BAdI class for decision handling.
The BAdI class implementation for decision handling is going to be dependent on the workflow, the task, and the BOR object dialog method that the task is bound to. You will need to examine all of those elements to determine the necessary implementation. In any case, you will be making use of the SAP_WAPI* business workflow functions.
In your enhancement implementation, switch to the Enh. Implementation Elements tab and double-click the Implementing Class node.

Double-click the method on the right-hand side.

In the Create Method Implementation dialog box, choose Yes.

Switch to change mode and add the required code, overwriting the existing code in the method.

Overwrite the method and endmethod lines in the existing code. Here is the code being implemented in the method:
Code Snippet123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081DATA ls_object TYPE swr_obj_2. DATA lv_objtype TYPE swr_struct-object_typ. DATA lv_objkey TYPE SWR_STRUCT-OBJECT_KEY. DATA lv_retcode TYPE sy-subrc. DATA lt_container TYPE TABLE OF swr_cont. DATA ls_container_line TYPE swr_cont. DATA FORMNUMBER TYPE SWXFORMABS-FORMNUMBER. DATA ls_formabs TYPE swxformabs. "Access the workflow data CALL FUNCTION 'SAP_WAPI_GET_OBJECTS' EXPORTING workitem_id = is_wi_details-wi_id IMPORTING leading_object_2 = ls_object. "Get the formnumber which is the key to the absence table MOVE ls_object-instid TO formnumber. "Select the details of the absence from the table SWXFORMABS select single * from swxformabs into ls_formabs where formnumber = formnumber. "Read the workflow's container data CALL FUNCTION 'SAP_WAPI_READ_CONTAINER' EXPORTING workitem_id = is_wi_details-wi_id IMPORTING return_code = lv_retcode TABLES simple_container = lt_container. " Check which decision was selected and set the data " values appropriately CASE iv_decision_key. WHEN 0001. "Approved ls_container_line-value = 'A'. ls_formabs-procstate = 'A'. WHEN 0002. "Rejected ls_container_line-value = 'R'. ls_formabs-procstate = 'R'. ENDCASE. "_WI_RESULT is what the workflow keys off to determine "which path to follow - Approve or Reject path ls_container_line-element = '_WI_RESULT'. "Modify the workflow's container data - we are updating the row that "holds _WI_RESULT which will be in the second row of the table MODIFY lt_container INDEX 2 FROM ls_container_line TRANSPORTING value. "Write the updated container back to the workflow engine CALL FUNCTION 'SAP_WAPI_WRITE_CONTAINER' EXPORTING WORKITEM_ID = is_wi_details-wi_id DO_COMMIT = 'X' IMPORTING RETURN_CODE = lv_retcode TABLES SIMPLE_CONTAINER = lt_container. IF lv_retcode NE 0. "Handle error ENDIF. "Update the Absence table with the updated data ls_formabs-approvdate = sy-datum. ls_formabs-approvby = sy-uname. update swxformabs from ls_formabs. "Complete the task CALL FUNCTION 'SAP_WAPI_WORKITEM_COMPLETE' EXPORTING WORKITEM_ID = is_wi_details-wi_id. "This task requires a confirm to be fully completed "and start the next step in the workflow CALL FUNCTION 'SAP_WAPI_WORKITEM_CONFIRM' EXPORTING WORKITEM_ID = is_wi_details-wi_id.Save and activate your changes.

In the Inactive Objects for Fiori dialog box, choose the green check mark.

Test the scenario: approve from SAP Fiori Approve Requests.
Launch the SAP Fiori launchpad by going to Google Chrome and choosing the Launchpad quick link. If prompted, enter your logon credentials.
Choose the My Inbox tile we created in an earlier step.
Choose the Approve icon.

Make a comment and choose Submit.
You should receive a successful message and the workflow item should be removed from the list. If not, clear the browser history and close, then reopen the launchpad.













