In this use case, I am adding custom pre-condition in workflow at item level for purchase requisition, so once you create Purchase Requisition and click on save, workflow will get triggered and will be sent for approval at Item Level.
I have created purchase requisition with "Supplier Material Number" and defined custom pre-condition for this supplier material number in workflow. If the value of supplier material number matches with defined pre-condition, then workflow will get triggered.
Reproducing the Issue
SAP has delivered a set of pre-conditions and step conditions. We can additionally define our own pre-condition / step condition using the custom BADI.
Before Implementation of BADI for custom Pre-Condition, below are list of some standard pre-conditions in purchase requisition.
Once BADI's are implemented, then those pre-condition / step condition will be visible in above list of Manage Workflows for purchase requisition app for the respective filter criteria.
We need to evaluate the defined pre-condition / step condition against the newly created BO using BADI.
Both BADI’s needs to be implemented in order to define and evaluate new custom pre-condition / step condition
Filter Conditions would be the scenario ID. The following are some of the scenario ID’s that can be used:
WS00800157 - Release of Purchase Requisition Header Level
WS00800173 - Release of Purchase Requisition Item Level
WS02000434 - Release of Central PR Header Level
WS02000438 - Release of Central PR Item Level
WS02000458- Release of Purchase Requisition for header level using the APP Manage Workflow for Purchase Requisitions – New
WS02000471- Release of Purchase Requisition for item level using the APP Manage Workflow for Purchase Requisitions – New
WS00800251- Workflow for blocked invoices
WS00800303 - Workflow for parked invoices as complete
WS00800238 - Workflow for Purchase Orders.
#Step 1 :-
New pre conditions can be defined using custom BADI SWF_WORKFLOW_CONDITION_DEF.
Defined pre-condition / step condition needs to be evaluated using BADI SWF_WORKFLOW_CONDITION_EVAL
Go to App "Custom Fields and Logic"->Custom Logic.
Go to Top right corner of this APP and click on "+" for creating new BADI Implementation.
It will ask for New Implementation Details
Business Context:Start and Pre-Condition in Flexible Workflow.
BAdI Description:Providing additional conditions for scenario.
New BADI has been created, go to documentation tab and read implementation usage.
We need to define filter condition based upon scenario id, so the precondition will only be visible to that scenario.
Go to filter tab and give scenario id, list of scenario id is mentioned above.
Scenario Id for Release of purchase Requisition Item is WS02000471.
Some Sample Code for understanding
ID : Unique ID, Subject : Name of Additional Condition, Type : Condition to be added at Step Level.
XSD_type : data type of additional condition and mandatory indicator.
data : ls_condition like line of ct_condition.
data : ls_parameter like line of ct_parameter.
ls_condition-id = 1.
ls_condition-subject = 'BAdI: Procurement for Supplier Material XYZ'.
ls_condition-type = if_swf_flex_ifs_condition_def=>cs_condtype-start_step.
append ls_condition to ct_condition.
SONT_KEY_PART_2 -> Purchase requisition item number
condition_id -> Unique ID of the additional condition
Name -> Name of parameter in workflow in Manage workflow app
Value -> Value of parameter mentioned in workflow in Manage workflow app
Should be set as true if the additional condition evaluation is successful
Check the sample code that can be used.
CV_IS_TRUE is parameter to activate the workflow,
cv_is_true = abap_false.
Reading parameter table with Pre condition that i have set in first BADI implementation.
READ TABLE it_parameter_value INTO DATA(ls_param_value)
WITH KEY name = 'XYZ'.
2. Get the data of Purchase requisition from API where sont_key_part_1 is the PR number and sont_key_part_2 is the PR item number.
SELECT * INTO TABLE @lt_purchaserequisition
WHERE purchaserequisition = @is_sap_object_node_type-sont_key_part_1
AND purchaserequisitionitem = @is_sap_object_node_type-sont_key_part_2.
4. Checking the condition step and maintained value for XYZ in supplier material number", if Pre-condition is XYZ and supplier material is also XYZ then workflow is activated for this custom pre condition.
READ TABLE lt_purchaserequisition INTO DATA(ls_purreq)
WITH KEY SupplierMaterialNumber = ls_param_value-value.
IF sy-subrc = 0.
cv_is_true = abap_true.
cv_is_true = abap_false.
cv_is_true = abap_false.
Click on save draft and publish the logic.
#Step 3: -
Create the Workflow
Go to App "Manage workflow app for purchase requisition" .
Select the scenario "Release for purchase requisition item" because we have given filter condition during BADI implementation.
Now the list has been extended with new custom pre-condition. Select Procurement for supplier material XYZ.
Select recipient in the step sequence to whom you send the mail for approval.
Click on SAVE and Active to activate the workflow.
Note:- Please keep the order of this new workflow at 1st position, because system is checking the order in which workflow is defined and then if there is any pre-conditions defined to start the workflow. At a time only one workflow will get trigger who satisfy the condition and was top in order.
Create Purchase Requisition: -
Go to App "Manage Purchase Requisition".
Now Create Purchase Requisition with value in Supplier material number as 'XYZ' and SAVE, custom workflow will get trigger for approval.
Check your inbox, go to workflow and check the status.
I have tested by approving the workflow and then go to step condition where I can see my start pre-condition BAdI: Procurement for XYZ are met that I have defined in workflow.
Learn > Share > Grow
Lot more to come. Stay tuned for my next blog post about data accessing techniques in SAP S/4HANA Cloud Fragmented Forms.