SAP Flexible Workflow Custom Scenario development with My Inbox Integration
Flexible Workflow is a new concept introduced in SAP S/4HANA with the objective to simplify workflow configuration. It is recommended that we use the new Flexible Workflow functionality in S/4HANA.
The flexible workflow is based on a set of predefined workflow scenarios and tasks. This provides the functionality to define condition-based workflow for different processes in the system.
It is possible to define single or multi step approval processes, and the relevant workflow items are made available in the My Inbox Fiori App for the approvers. Manage Workflows Fiori App is available to configure flexible workflow scenario, and these apps allow the Business process specialist to set up workflows based on the business requirement.
SAP pre-delivered many such flexible scenario in procurement, finance etc. and SAP help is available to set up/activate those templates. However, I found some difficulty to create custom template by using this new technology and integrate them in my inbox. To address that, I have prepared this blog post to fulfil one simple multi step scenario which we come across in every implementation.
2. Multi step Approval/Reject Scenario
3. Objects Involved in this development
- Flexible workflow scenario Development
- Responsibility rule to get L1 approver
- Workflow Class to manage workflow
- My inbox task configuration
- Manage Workflow setup for custom workflow
- Email Templates
4. Flexible Scenario development:
Tcode : SWDD_SCENARIO
New tcode being used to create flexible scenarios in S4 system. Flexible block is the main component which will play important role in scenario. We have to first decide all possible decision tasks and activities (background method executions) as per business requirement. As per our sample workflow, we have 3 decision tasks and 1 activity.
Create new flexible workflow scenario with class based.
Create one container element employee of class type to hold all employee object details.
Go to Header and update start event details. I have created one START event in custom class which will be used to trigger this WF.
Create all required activities as per business requirement. As per our sample requirements, we have user decision steps like Level1 Approval, Level 2 Approval, To Requestor and activity like Post Employee data by final approver.
Create all required Agent rules as per business conditions. For the sake of POC, I have used one responsibility rule with one agent maintained manually to get L1 Approver. But in real time scnario, these agents will be determined in FM based on some roles or any other conditions. That FM being used in PFAC rule.
The moment we create activities in Flexible block, it will ask us to provide all task details for that activity. We need to provide required task details whether user decision or activity. I’m not going too much here as this is normal workflow functionality. The moment we create activity, then flow will be created for this activity. Since we have 4 activities in sample workflow, so we can see 4 flows visible in this workflow.
5. Workflow Triggering logic (Workflow class logic )
Flexible workflow triggering is just same as classic workflow mechanism. We can trigger this either by using BO or Class events. I have created one simple method in class to trigger this wf with some event parameters. I’m passing employee details to workflow through start event for the sake of POC.
Redefine standard WF interface methods at least with empty implementation and activate class.
I have declared one public key attribute in this class and instantiated this value in constructor of the class.
START Event to trigger workflow
STARTWF method code to trigger this workflow: Below is the sample code to trigger workflow. In real time situations, you can use your own event parameters and populatate those. Based on your requirement, we will call this event in some exits, BADIs, Odata function imports or create/update methods or custom programs etc.
DATA lv_objkey TYPE sibfinstid.
DATA ls_empdetails TYPE zhcm_st_telecommuting.
DATA lv_param_name TYPE swfdname.
DATA lr_event_parameters TYPE REF TO if_swf_ifs_parameter_container.
DATA g_evt_param_container TYPE REF TO if_swf_cnt_container.
DATA l_event_ref TYPE REF TO if_swf_evt_event.
DATA vl_returncode TYPE sysubrc.
DATA l_objtype TYPE sibftypeid VALUE ‘ZCL_WF_EMPLOYEE_FLEX’. DATA l_event TYPE swo_event VALUE ‘START’.
DATA l_event_container TYPE REF TO if_swf_ifs_parameter_container.
lv_objkey = iv_employee.
CALL METHOD cl_swf_evt_event=>get_event_container
im_objcateg = cl_swf_evt_event=>mc_objcateg_cl
im_objtype = l_objtype
im_event = l_event
re_reference = lr_event_parameters.
ls_empdetails-ei_employeeno = iv_employee.
ls_empdetails-ei_lastname = ‘Veshala’.
ls_empdetails-ei_firstname = ‘Naveen’.
ls_empdetails-ei_postitle = ‘Consultant’.
ls_empdetails-hr_telestartdate = sy-datum.
lv_param_name = ‘EMPDETAILS’.
CALL METHOD lr_event_parameters->set
name = lv_param_name “#EC NOTEXT
value = ls_empdetails.
CALL METHOD cl_swf_evt_event=>raise
im_objcateg = cl_swf_evt_event=>mc_objcateg_cl
im_objtype = l_objtype
im_event = l_event
im_objkey = lv_objkey
im_event_container = lr_event_parameters.
6. Manage Workflow App – Workflow development and activation
Open Manage Workflow app in Fiori launch pad and configure new workflow based on our custom template. As per our flow, we have 3 steps in workflow, L1 approval, L2 approval and finally posting data into SAP. When L1 or L2 clicks on Return button , then workitem routed back to Requestor and then restart workflow when Requestor clicks on Resubmit button. Let us configure workflow to fulfil this business scenario.
Open our custom scenario in Manage Workflow fiori app and click on + add button to create new workflow
Valid from and Valid to need to updated if we want to configure workflow for certain period of time else, leave it blank.
Configure steps. Click on Add in step sequence section and create new step.
Choose Level1Approver Agent role in receipents. Pls note that these roles are coming from Agent Rules in Flexi block. So based on our business requirement, we have to create different rules to determine agents and use those rules in workflow step configuration.
Add Exception Handling actions as per our flow.
If approver Rejects – then workfow would get cancelled.
Returns – Then workflow routed back to Requestor.
Note : I have used our other decision step To Requstor as required action for Return action and selected Restart workflow as action result. Due to this, When requstor clicks on Resubmit button, it will again routed back to L1 Approval for review and approval.
Similarly, add other 2 steps as well.
Save and Activate workflow.
7. My Inbox Task Configuration
Generally, we will activate task filter in real time scenario to display ONLY required workflow tasks work items in My Inbox App. So, unless we add these in Task settings, new decision tasks won’t be displayed in My Inbox app.
SPRO->SAP Netweaver -> SAP Gateway Service Enablement -> Content -> Workflow Settings -> Maintain Task Names and Decision Options
Sample Decision Keys for Return to Tequestor task, These desions will be displayed as buttons in My Inbox App.
Note: These are minimum steps needed to create one custom scenario and expose it to My inbox app. Let us start testing now.
Login with requestor role and execute test method STARTWF in our workflow class.
Login fiori launchpad with Level 1 Approver and check the work item in My Inbox app.
Click on Return button . As per our flow, it will be routed back to requestor.
Click on Resubmit, Workflow will restart again and work item goes to L1 Approver for approval.
Resubmitted by requestor and approved by L1. Workitem is awaiting final approval now.
Final L2 approver approved. As per flow, it called background activity and posted data and log updated and workflow got completed.
9. Dead line Monitoring :
From S4 1909 onwards, SAP has provided to enable dead line feature for decision taks steps in Manage workflow configuration.
As shown below , overdue item was triggered after 10 min and reflected that in SBWP and My Inbox app of L2 approver.
10. Email Templates
SAP provided Email template options to generate emails through flexible workflow scenario. Email template name plays main role while sending mail. We have to follow same naming convention as per our scenario to send email.
Copy Pre-delivered email template SWF_CRT_NOTIFY_RECIPIENTS and make changes as per your business requirement in custom template. When copying, you can name custom template as per your scenario correctly.
To send email before particular task id : YY1_(Scenario_ID)_CRT_(StepID)
For Ex : YY1-ZZ1_YY1_90000005_CRT_87 to send mail for L2 Approver
To send mail to requestor after completion of workflow with Approved or Rejection
Approve – YY1_(Scenario_ID)_COMPLETE_POSITIVE
Rejected – YY1_(Scenario_ID)_COMPLETE_NEGETIVE
Create one email template for L2 Approver as shown in below screenshot
With this i conclude this blog post. My intenstion is to keep all required steps in this blog post, so it is useful to others as well.
I have referred other blog posts and taken flexible workflow introduction from below blog post.
References : https://blogs.sap.com/2020/08/25/flexible-workflow-for-sourcing-and-procurement-in-sap-s-4hana/ – Introductory text
www.help.sap.com – Overall documentation
Email Templates : How to set up email template in flexible workflow..
- When configuring ATO ( S_ATO_SETUP ) for in app enhancements, use prefix YY1_ , then we can able to create all email templates like for final approal (YY1_(Scenario_ID)_COMPLETE_POSITIVE) or rejection (YY1_(Scenario_ID)_COMPLETE_NEGETIVE) as per SAP naming standards, Otherwise,it will not take that much name like ZZ1_YY1_*.
- If you want to enable dead line monitoring email notification in custom scenarios , then create that template in backend ( SWDD_SCENARIO) and then we will get email options in Manage workflow app.
- In above example, i have used seperate background task to update the data in to SAP . How ever, we can still wrtie this code in flexible workflow run time adopter class which is inherited from standard class -CL_SWF_FLEX_IFS_RUN_APPL_BASE. You can check this class in SWDD_SCENARIO – control tab of scnario definition.