Friday, 6 November 2020

Changing Work-item Initiator in a Workflow.

Introduction:

Usually, for a workflow with multiple steps in Approval process, the Work item initiator is the user who processed the previous step/ created the current step and sometimes, technically it is shown as “WF-BATCH” which is technical workflow system user.

I came across this situation where my client wants to see the User who triggered/initiated the workflow in his FIORI MY-INBOX, instead of the user who created the current step ( i.e, who processed previous step/ Work-Item initiator ) which in my case was being shown as “WF-BATCH”.

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

I have found two approaches for this.

1. Changing the Workflow user using an update statement.
2. Providing the Username in the Dialogue step of the of the Workflow while creating the workflow.

Approach 1: Changing the Workflow user using an update statement

This approach can be used if your workflow and its steps are processed programmatically.

Table SWWWIHEAD stores the Header details of all types of Work items. The field ‘WI_CRUSER’ stores the Name of the user who created the Work Item.

Updating the field WI_CRUSER in the Table SWWWIHEAD for the New Work item is one approach to solve this issue.

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

In this approach, I have triggered my WF manually using the below series of steps:

Step 1: Triggering the WF using the Below FM

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

Approval steps are also processed manually.

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

Step 2: FM: SAP_WAPI_GET_DEPENDENT_WIS is used to get the list of Work items under the main/Top Work-item. Looping them and obtaining the latest work-item.

Step 3: Using the FM: SAP_WAPI_WRITE_CONTAINER I am sending the user decision as Approved ( Refer Above screenshot for container values)

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

Step 4: I have processed my current step FM: SAP_WAPI_WORKITEM_COMPLETE.

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

Step 5: After processing the current step, I have obtained the newly generated Work Item and updated the table SWWWIHEAD table record for that Work item. (Field WI_CRUSER is updated for the newly generated Work item).

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

Make sure to store the Top WIID somewhere to perform approval steps further.

Approach 2: Providing the Username in the Dialogue step of the of the Workflow while creating the workflow

In the Workflow step, navigate to the properties tab. Property tab here, is basically a name-value pair where we provide the Property and its value.

Pass the value of the User name to the property “sap.bc.bmt.wfm.initiator” as shown below.

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

The container ‘_Workitem’ is a structure that stores the details of the Workflow on its first call:

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

Before:

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

After changing the Work-item Initiator using above procedures:

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

Table: SWWWIHEAD

Before Implementation

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

After Implementation:

SAP ABAP Exam Prep, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Career

No comments:

Post a Comment