S/4 Purchase Order Flexible Workflow: Agent Determination by BADI
As you know, in S/4 we have the Flexible Workflows scenarios. In some business cases, the standard agent determinations is not enough to meet the company’s needs, so we need to add custom code to make it 100%. On the Agent determination side, we have BADIs to accomplish that. Here, i’m gonna show how to use the Agent Determination BADI on the Purchase Order approval Flexible Scenario.
If you want more details on how to implement this flexible scenario, follow the tutorial here.
The Purchase Order approval Flexible Scenario (SWDD_SCENARIO) is: WS00800238:
If you select the flexible process:
In the Agent Rules tab, you see all the available options that the user can select when configuring the Flexible Scenario:
On the FIORI App:
If you select the BADIAgentDetermination, you’ll see that it uses the 00800036 Rule (PFAC):
And in there, it calls the FM MMPUR_WFL_PO_BADI_AGENTS:
Cool, so now we now the how it get’s done. But now, i want to insert my Custom Code on the process:
For that we need to implement BADI MMPUR_WORKFLOW_AGENTS_V2.
When you implement it, it even gives you the choice to copy the sample class:
After the correct implementation:
The GET_APPROVERS method is where our logic will be:
Inserted some sample code:
Here it is:
METHOD IF_MMPUR_WORKFLOW_AGENTS_V2~GET_APPROVERS. DATA: LS_BADI_APPROVER TYPE IF_MMPUR_WORKFLOW_AGENTS_V2=>BD_MMPUR_S_BADI_APPROVER. ** DEMO IF PURCHASINGDOCUMENT EQ '0010203040'. LS_BADI_APPROVER-BUSINESSUSER = 'WF-BATCH'."Sample user here, could be anyone... LS_BADI_APPROVER-APPROVALLEVEL = 1. APPEND LS_BADI_APPROVER TO APPROVERLIST. ENDIF. ENDMETHOD.
So now, testing the rule (in PFAC) by passing the 10203040 PO, i’m getting the user as the Agent. Now, he would be getting the Workflows for approval, if the BADI Agent Determination is selected in any Flexible Workflow process for Purchase Order.