SAP Knowledge Base Article - Public

2841783 - How to define new Pre-condition in Manage Workflow for Purchase orders

Symptom

New Custom Pre-Condition need to be created in :  New BADI available in 1902 S4HC.

New pre-conditions can be defined in Manage workflow app. Custom Logic app be used to create a BAdI implementation and publish the custom logic.

Environment

SAP S/4HANA Cloud Public Edition 1902 and higher version

Reproducing the Issue

SAP has delivered a set of pre-conditions and step conditions. Customers can additionally define their own pre-condition / step condition using the custom BADI. New conditions can be defined using custom BADI SWF_WORKFLOW_CONDITION_DEF.      Once this BADI is implemented, then those pre-condition / step condition will be visible in the Manage Workflows app for the respective filter criteria.

The defined pre-condition / step condition needs to be evaluated against the newly created PO. That will be done using the custom BADI SWF_WORKFLOW_CONDITION_EVAL.

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.  The scenario ID’s that can be used:

  1. WS00800238 - Workflow for Purchase Order

 

You can find 2 new BADIS in the Flexible Workflow Framework for Purchase Requisitions:

BADi - SWF_WORKFLOW_CONDITION_DEF,  Method  : GET_CONDITIONS

Use : to define additional conditions for scenarios

BADi - SWF_WORKFLOW_CONDITION_EVAL,  Method  : EVALUATE_CONDITION

Use : to evaluate the additional conditions defined

 

Resolution

Check the following technical documentation and sample code for the BADIS:

 

BADi - SWF_WORKFLOW_CONDITION_DEF,  Method  : GET_CONDITIONS

Use : to define additional conditions for scenarios

Parameters :

  • CT_CONDITION

Fields :-

  • ID : Unique ID of the additional condition
  • subject : Name of the additional condition
  • type : Condition to be added at step level(type = if_swf_flex_ifs_condition_def=>cs_condtype-step) or at both of step level and workflow level(type = if_swf_flex_ifs_condition_def=>cs_condtype-start_step)
  • CT_PARAMETER

Fields :-

  • ID : Unique ID of the additional condition
  • Name : Name of the additional condition
  • xsd_type : Data type of the additional condition(supported data types are Boolean, date, string, integer and time)
  • mandatory : To indicate the additional condition is mandatory

 

Sample code for adding additional condition delivery date at both step and workflow level:-

ct_condition = VALUE #(

 

            ( id = 1 subject = 'BADI: Custom Condition'(001) type = if_swf_flex_ifs_condition_def=>cs_condtype-start_step ) ).

 

    ct_parameter = VALUE #(

 

            ( id = 1 name = 'BADI: Custom Condition'(001)     xsd_type = if_swf_flex_ifs_condition_def=>cs_xstype-date   mandatory = abap_true )

 

).

BADi - SWF_WORKFLOW_CONDITION_EVAL,  Method  : EVALUATE_CONDITION

Use : to evaluate the additional conditions defined

Parameters:

  • IS_SAP_OBJECT_NODE_TYPE

Fields:-

  • SONT_KEY_PART_1-> Purchase Order
  • IS_CONDITION

Fields:-

  • condition_id -> Unique ID of the additional condition
  • IT_PARAMETER_VALUE

Fields:-

  • Name -> Name of parameter in workflow in Manage workflow app
  • Value -> Value of parameter mentioned in workflow in Manage workflow app
  • CV_IS_TRUE

Should be set as true if the additional condition evaluation is successful

 

Sample code for evaluating additional condition – Custom Field: -

 

 

data: lv_custom_field type yy1_ext_test1.

 

 

    IF ( is_condition-condition_id > 1 ).

 

      RAISE EXCEPTION TYPE cx_ble_runtime_error

 

        EXPORTING

 

          previous = NEW cx_swf_flex_lra( textid = cx_swf_flex_lra=>condition_not_supported ).

 

    ENDIF.

 

    cv_is_true = abap_false.

 

*

 

        SELECT  SINGLE * INTO  @DATA(ls_purchaseorder)

          FROM i_purchaseorderapi01

           WHERE purchaseorder = @is_sap_object_node_type-sont_key_part_1.

 

    IF sy-subrc <> 0.

 

      RAISE EXCEPTION TYPE cx_ble_runtime_error

 

        EXPORTING

 

          previous = NEW cx_swf_flex_lra( textid = cx_swf_flex_lra=>object_instance_not_found ).

 

    ENDIF.

 

 

    READ TABLE it_parameter_value INTO DATA(ls_param_value)

 

      WITH KEY name = 'BADI: Custom Field'.

 

    IF sy-subrc EQ 0.

      lv_custom_field = ls_param_value-value.

    ENDIF.

 

 

    CASE is_condition-condition_id.

     WHEN 1.

      IF lv_custom_field = ls_purchaseorder-<customfield>.

          cv_is_true = abap_true.

      ENDIF.

  ENDCASE.

See Also

If parameter @is_sap_object_node_type-sont_key_part_1 is empty during debugging, the reason is that the BAdI is called twice. First called as a part of the simulation and the document is not yet posted. Which means the document number has not yet been generated. Hence you cannot have the document number at this point in time when BAdI is called. However, the BAdI is called again for the second time in the update task when the workflow user SAP_WFRT triggers the workflow. By now, the document is already created and this BAdI is called by the workflow triggering/processing user SAP_WFRT. So to have the PO number in the BAdI during debugging, activate the update task debugging session and keep external breakpoints for user SAP_WFRT. ( Debugging mode can only be activated for SAP S/4HANA Cloud Public Edition 3SL on ADT )

Keywords

@is_sap_object_node_type-sont_key_part_1 , KBA , MM-FIO-PUR-PO-WFL , Purchase Order Workflow , MM-FIO-PUR-PO , Fiori UI for Purchase Orders , Problem

Product

SAP S/4HANA Cloud Public Edition all versions