How to Send Workflow Notification as Email in Sap
"© 2020. SAP SE or an SAP affiliate company. All rights reserved." "Used with permission of SAP SE"
This blog post is to provide solution to the recent problem I faced with SAP Fiori My Inbox App and Notification Center to everyone.
Presumptions
- My Inbox Fiori App has been configured
- Notification Center (if required) has been configured
Problem
I faced this problem when I used the Send Mail step to send Notification in a Workflow.
In SAP GUI it was working perfectly. These get displayed in Unread Documents/Documents Category of SAP Business Workplace (SBWP) –
But these were missing in the My Inbox app and also the Notification Center . While trying to find a solution for this, I saw the SAP Note shown below and came to this conclusion –
My Inbox app and Notification Center in Fiori Launchpad do not support the Background Tasks of the Workflow. Only the workitems of User Decision dialog steps/tasks are shown there.
Solution
Go to the Control Tab of the Workflow Step and open the Task –
To make it a User Decision Task, Uncheck the Background Processing Checkbox and Check the Confirm end of Processing as shown below –
Confirm end of Processing will create buttons called " Complete Workitem " and " Complete " in SAP Business Workplace (SBWP) and My Inbox app respectively. These buttons are used to complete the Workitem. After this user action, it will be moved out of My Inbox and Open Workflow Items in SBWP (It will be still in Documents category of SBWP).
After making this change, the workitem will start appearing in My Inbox and Notification Center . And our 1st milestone has been achieved. ?
So, moving forward to the next step. As you can see in the screenshot below, the User Decision button " Complete " is missing in Fiori My Inbox app –
Because of this it will never move out of My Inbox , as a result it will get loaded with too many Send Mail Workitems.
When I tried to open it in SAP Business Workplace (SBWP) , I got this pop up to Complete Workitem –
I just pressed " Cancel " button and immediately after this the " Complete " Button became visible in My Inbox –
It means once Workitem is opened and its status gets changed to " COMMITTED " only then " Complete " button is displayed in My Inbox . But if we always have to open the Workitem/Task first in SBWP, then what's the use of Fiori My Inbox? That's why, now our milestone is to automatically get this " Complete " button in My Inbox without opening the same in SBWP .
For this, I created a small Report in SAP – Z_NOTIF_WF_EXECUTE
REPORT z_notif_wf_execute. * Local Types Declaration TYPES: BEGIN OF lty_status, wi_id TYPE swwwihead-wi_id, subrc TYPE sy-subrc, END OF lty_status. * Local Data Declaration DATA: lt_status TYPE STANDARD TABLE OF lty_status, lv_subrc TYPE sy-subrc. SELECT wi_id FROM swwwihead INTO TABLE @DATA(lt_wi_id) WHERE wi_rh_task EQ 'TS90000011' AND wi_stat EQ 'READY'. LOOP AT lt_wi_id ASSIGNING FIELD-SYMBOL(<fs_wi_id>). CLEAR: lv_subrc. CALL FUNCTION 'SAP_WAPI_EXECUTE_WORKITEM' EXPORTING workitem_id = <fs_wi_id>-wi_id IMPORTING return_code = lv_subrc. APPEND INITIAL LINE TO lt_status ASSIGNING FIELD-SYMBOL(<fs_status>). <fs_status>-wi_id = <fs_wi_id>-wi_id. <fs_status>-subrc = lv_subrc. ENDLOOP.
Here, I am simply selecting the new workitems, of the Send Mail Task we are getting in SBWP and My Inbox , which are still in status " READY" . Then using the FM – SAP_WAPI_EXECUTE_WORKITEM, all these workitems are executed.
In the Backend, FM – SWW_WI_POPUP_FOR_COMPLETION gets called. This is the FM which shows the pop up in SBWP with Complete Workitem and Cancel buttons. But we can not do this manually (because later on this report will be set as a background job ?), so I created a very small Enhancement – Z_NOTIF_MYINBOX in this FM, right at the beginning –
FUNCTION sww_wi_popup_for_completion. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Function Module SWW_WI_POPUP_FOR_COMPLETION, Start A *$*$-Start: (1)---------------------------------------------------------------------------------$*$* ENHANCEMENT 1 Z_NOTIF_MYINBOX. "active version *&--------------------------------------------------------------------&* *& Revision Log &* *& Date : 02-Jun-2020 &* *& Author : Harsh Bansal (BANSAL) &* *& Revision Tag : Initial Version &* *& Description : Notification Workflow Enhancement to generate &* *& Complete Button in Fiori MyInbox &* *&--------------------------------------------------------------------&* IF sy-tcode NE 'SBWP' AND wi_header-wi_rh_task EQ 'TS90000011' AND sy-cprog EQ 'Z_NOTIF_WF_EXECUTE'. CLEAR: decision. container_invalidated = abap_true. RETURN. ENDIF. ENDENHANCEMENT.
I have put checks for the validation of Enhancement execution –
- To be ignored for SBWP , because we need the pop up there
- Only to work for the Send Mail Task and the Custom Report created above
Variable ' decision ' gets the value in this FM after the user action. In case of,
- Button – " Complete Workitem ", decision = 1, and for
- Button – " Cancel ", decision = space
That's why, I have cleared the variable ' decision ' and moved out of the FM ( RETURN ). Because of this, pop up will not be triggered and user action has already been filled as space to consider " Cancel ". So, workitem execution will get completed with " Cancel" action being considered as taken and status of the workitem will get changed to " COMMITTED ". This will make sure that we will get the " Complete " button in My Inbox app.
Now, the last step is to schedule a Background Job to keep running the report created above, Z_NOTIF_WF_EXECUTE , every minute (to keep My Inbox updated) –
Conclusion
Changes to be done –
- Uncheck Background Processing and Check Confirm end of Processing in Send Mail Task
- Report to execute the new Workitems
- Background Job to run the report
That's it, now every minute this Background Job will keep running the Custom Report in the backend, which will keep selecting the new workitems of Send Mail Task which are still in " READY " status and have not been changed to " COMMITTED " yet. Then simply Workitem execution will be done for all these with user action of " Cancel " button.
Voila! We have reached our goal ?
Thank You !!
How to Send Workflow Notification as Email in Sap
Source: https://sapbazar.com/articles/item/3359-how-to-display-background-send-mail-workflow-task-in-sap-fiori-my-inbox-and-notification-center
0 Response to "How to Send Workflow Notification as Email in Sap"
Post a Comment