SAP MDG · WORKFLOWS

How does dynamic agent determination work in SAP MDG rule-based workflow, and how do I implement the context preparation for a custom workflow scenario?

Dynamic agent determination in this MDG example is implemented in a custom class that prepares BRF+ rule context, derives the workflow scenario from the change request, resolves the BRF+ element ID for the scenario field, and can also read the current workflow step and last processor from workflow containers.

Dynamic agent determination in this MDG example is implemented in a custom class that prepares BRF+ rule context, derives the workflow scenario from the change request, resolves the BRF+ element ID for the scenario field, and can also read the current workflow step and last processor from workflow containers.

Dynamic agent determination in this MDG example is driven by a custom rule-context class. The class prepares the BRF+ context for the workflow, derives a scenario from the change request, and then passes that scenario into the rule engine so the workflow can route to the correct dialog or automatic path. It also contains helper logic to read the current workflow step and the last processor from the active workflow instance.

Process flow

  1. Read the change request type from `USMD120C` or fall back to the application context.
  2. Derive the workflow scenario from the change request data and requestor roles.
  3. Resolve the BRF+ element ID for `ZSCENARIO` using `CL_USMD_WF_SSW_RULE_SERVICE` and `CL_FDT_FACTORY`.
  4. Create a context value of type `ZMDG_DE_CUST_WF_SCENARIO` and assign the scenario.
  5. Append the context row to `ET_RULE_CONTEXT_VALUE` in `IF_USMD_SSW_RULE_CNTX_PREPARE~PREPARE_RULE_CONTEXT`.
  6. If required, read the current workflow step and last processor from `SWWWIHEAD` and `SAP_WAPI_READ_CONTAINER` for troubleshooting or follow-up logic.
BRF+

Application / Data Object / Element lookup for the CR-type-specific application

Maintain the BRF+ data object element that the rule-context code resolves by name, such as `ZSCENARIO`.

Referenced tables

ObjectPurpose
USMD120CStores change request header data, including CR type and created-by information used by the context logic.
USMD1210Change request note table referenced in the same MDG utility landscape for workflow-related annotations.
SWWWIHEADWorkflow item header table used to identify the latest workflow item and current processor.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1class ZCL_MDGC_RBW_DYN_CONTEXT definition 2 public 3 final 4 create public . 5 6public section. 7 8 interfaces IF_BADI_INTERFACE . 9 interfaces IF_USMD_SSW_RULE_CNTX_PREPARE . 10 11 class-methods GET_WORKFLOW_PROCESSOR 12 importing 13 !IV_CR_NUMBER type USMD_CREQUEST 14 exporting 15 !EV_STEP type USMD_CREQUEST_APPSTEP 16 !EV_LAST_PROCESSOR type XUBNAME . 17protected section. 18private section. 19 20 class-methods GET_ELEMENT_ID 21 importing 22 !IV_CR_TYPE type USMD_CREQUEST_TYPE 23 !IV_NAME type IF_FDT_TYPES=>NAME 24 exporting 25 !EV_BRF_EXPR_ID type IF_FDT_TYPES=>ID . 26 class-methods GET_SCENARIO_ID 27 importing 28 value(IV_CR_TYPE) type USMD_CREQUEST_TYPE optional 29 !IV_COMMCODE type MATKL 30 !IV_ZCOM_D_I type ZCOM_D_I 31 value(IV_ACCGROUP) type KTOKK optional 32 value(IV_IS_CRITICAL) type BOOLE_D optional 33 exporting 34 !EV_SCENARIO type ZMDG_DE_CUST_WF_SCENARIO 35 !EV_ERROR_DESC type NATXT . 36 class-methods GET_SCENARIO_FROM_CR 37 importing 38 value(IV_CREQUEST) type USMD_CREQUEST optional 39 exporting 40 value(EV_SCENARIO) type ZMDG_DE_CUST_WF_SCENARIO 41 !EV_ERROR_DESC type NATXT . 42ENDCLASS. 43 44 45 46CLASS ZCL_MDGC_RBW_DYN_CONTEXT IMPLEMENTATION. 47 48 49method get_element_id. 50 data: 51 lv_application_id type if_fdt_types=>id, 52 lo_brf_factory type ref to if_fdt_factory, 53 lo_brf_query type ref to if_fdt_query, 54 lt_selection type if_fdt_query=>ts_selection, 55 ls_selection like line of lt_selection, 56 ls_obj_category type if_fdt_query=>s_object_category_sel, 57 lt_names type if_fdt_query=>ts_name, 58 ls_names type if_fdt_query=>s_name. 59 60*--------------------------------------------------------------------* 61 62 assert iv_cr_type is not initial. 63 assert iv_name is not initial. 64 65* get the ID of the brf+ application depending on the CR type 66 lv_application_id = cl_usmd_wf_ssw_rule_service=>get_cr_type_app_id( iv_cr_type ). 67 if lv_application_id is initial. 68 message x000(usmd1). "no brf+ application exists for this cr type 69 endif. 70 71 lo_brf_factory = cl_fdt_factory=>if_fdt_factory~get_instance( ). 72 73* create a query object instance ... 74 lo_brf_query = lo_brf_factory->get_query( 75 iv_object_type = if_fdt_constants=>gc_object_type_data_object 76 iv_data_object_type = if_fdt_constants=>gc_data_object_type_element ). 77 78* ... and define the selection criteria 79 ls_selection-queryfield = if_fdt_admin_data_query=>gc_fn_name. 80 ls_selection-sign = 'I'. 81 ls_selection-option = 'EQ'. 82 ls_selection-low = iv_name. 83 insert ls_selection into table lt_selection. 84 85 ls_selection-queryfield = if_fdt_admin_data_query=>gc_fn_application_id. 86 ls_selection-sign = 'I'. 87 ls_selection-option = 'EQ'. 88 ls_selection-low = lv_application_id. 89 insert ls_selection into table lt_selection. 90 91 ls_obj_category-system_objects = abap_true. 92 ls_obj_category-customizing_objects = abap_true. 93 ls_obj_category-masterdata_objects = abap_false. 94 95* select the data 96 lo_brf_query->select_data( 97 exporting 98 its_selection = lt_selection 99 is_object_category_sel = ls_obj_category 100 importing 101 eta_data = lt_names ). 102 103 read table lt_names into ls_names index 1. 104 ev_brf_expr_id = ls_names-id. 105 106endmethod. 107 108 109method get_scenario_from_cr. 110 types: 111 ty_r_fields type range of usmd_fieldname . 112 data: lt_crequest type sorted table of usmd_crequest with unique key table_line, 113 ls_crequest type usmd_crequest, 114 lt_changed_value type usmd_ts_change_document_value, 115 lt_changed_detail type usmd_th_change_document_change, 116 lt_changed_value_cusgen type usmd_ts_change_document_value, 117 lt_changed_detail_cusgen type usmd_th_change_document_change, 118 lt_changed_value_sales type usmd_ts_change_document_value, 119 lt_changed_detail_sales type usmd_th_change_document_change, 120 ls_change_fields type ty_r_fields,

The remaining configuration, implementation details, and testing guidance continue from this answer more…

Related questions and keywords

Alternative questions

  • How do I populate the BRF+ rule context for MDG workflow agent determination?
  • Which class prepares the dynamic workflow context for SAP MDG rule-based workflow?
  • How do I derive the workflow scenario and current processor in an MDG change request?

Possible questions

  • Which class prepares the workflow rule context for dynamic agent determination in MDG?
  • How is the BRF+ element ID resolved from the CR type and element name?
  • How do I read the current workflow step and last processor from an MDG change request?
  • How is the workflow scenario derived from the change request data?
  • What interfaces does the custom dynamic context class implement?

Keywords

SAP MDGrule-based workflowdynamic agent determinationBRF+IF_USMD_SSW_RULE_CNTX_PREPAREIF_BADI_INTERFACECL_USMD_WF_SSW_RULE_SERVICECL_FDT_FACTORYSAP_WAPI_READ_CONTAINERUSMD120CUSMD1210