cancel
Showing results for 
Search instead for 
Did you mean: 

MDG for Finance- How to Send an Email Notification to the Requestor during the Governance Process

AKHILARAPARTHI
Explorer

                    Email notifications play a pivotal role in the process of Data Governance . The main intention       of this blog post is to explain you about how to notify a requestor after the activation of change request which goes to various levels of approvers in the Governance Process.

                    In this blog post I pick up the scenario of sending out email to the requestor after the activation of Cost Centre Change Request  for Finance Module in Create  Process .

IMPLEMENTATION :

  To Implement this functionality, we need to follow 3 steps.

  1. Define 'Service Name' in MDG-Configuration.
  2. Mention Service Name in 'Decision Table' for Rule-Based Workflow.
  3. 3.Implement your custom logic in 'SYSTEM_METHOD_CALLER_BADI' & trigger the Email Code.

DEFINE 'SERVICE NAME' IN MDG-CONFIGURATION :

                                                                                      Go to MDGIMG ( t-code) .Execute the below steps to Create 'Service Name '.

DEFINE 'SERVICE NAME' IN MDG-CONFIGURATION :

                                                                                      Go to MDGIMG ( t-code) .Execute the below steps to Create 'Service Name '.

1.png

                         Fig 1 : Path to define Service Name

2.png

                               Fig 2 :  Define Service Name

  MENTION SERVICE NAME IN 'DECISION TABLE' FOR RULE-BASED WORKFLOW :

                                                      Add 'Service Name' in Non-User Agent Decision Table and Necessary step  for Single Valued Decision Table.     

3.png

                              Fig 3 : RBWF path

6.png

                 Fig 4 :  Change Request Type 4.png

                                 Fig 5 : Configuring Service Name in Decision Table

IMPLENTING CUSTOM LOGIC IN 'SYSTEM_METHOD_CALLER_BADI :   Go to SE18 ( t-code)

                   Enhancement Spot : 'USMD_SSW_SERVICE_PROCESSOR'.                  

                   BADI Name               : 'USMD_SSW_SYSTEM_METHOD_CALLER'.

                 Method Name          : 'IF_USMD_SSW_SYST_METHOD_CALLER ~                           CALL_SYSTEM_METHOD'

                 Importing Parameter : IV_SERVICE_NAME = 'ZCL_MDG_FI_ZCCT1P2'.

 Logic to handle Email :

 

METHOD if_usmd_ssw_syst_method_caller~call_system_method.
CASE iv_service_name.

WHEN 'ZMDG_FI_EMAIL_ZCCT1P2'.
 DATA : lr_model    TYPE REF TO if_usmd_model_ext,
              lr_crequest TYPE REF TO if_usmd_crequest_api.
 
       DATA : it_recepients   TYPE bcst_recipient,
              ls_recipient    TYPE Adr6,
              ls_crequest     TYPE usmd_s_crequest,
              iv_mail_subject TYPE bcs_subject,
              lt_data         TYPE usmd_t_crequest_entity,
              ls_data         TYPE usmd_s_crequest_entity,
              lt_errors       TYPE usmd_t_message,
              lv_content      TYPE string,
              lt_body_hex     TYPE solix_tab.
 
       DATA: lo_send_request  TYPE REF TO cl_bcs,
             lo_document      TYPE REF TO cl_document_bcs,
             lo_sender        TYPE REF TO cl_sapuser_bcs,
             lo_recipient     TYPE REF TO if_recipient_bcs,
             lo_bcs_exception TYPE REF TO cx_bcs,
             lv_mail_subject  TYPE bcs_subject,
             lv_att_size      TYPE sood-objlen,
             lv_text          TYPE string,
             lv_space         TYPE char10,
             lv_sub           TYPE so_obj_des.
 
       DATA : lv_dummy,
               lv_CC_number TYPE usmd_value.
**Get the details of the CR.
       CALL METHOD zcl_mdg_fi_utility=>read_cr_detail
         EXPORTING
           iv_cr_number = iv_cr_number
         IMPORTING
           es_crequest  = LS_crequest.
 
       CALL METHOD zcl_mdg_fi_utility=>read_entity_data
         EXPORTING
           iv_cr_number   = iv_cr_number
           iv_entity      = 'CCTR'
         RECEIVING
           rt_data_entity = lr_data.
       IF lr_data IS NOT INITIAL.
         READ TABLE lr_data INTO wa_data INDEX 1.
         ASSIGN wa_data-r_t_data->* TO <ft_data>.
         LOOP AT <ft_data> ASSIGNING <fs_data>.
           ASSIGN COMPONENT 'CCTR' OF STRUCTURE <fs_data> TO <fv_CCTR>.
           ASSIGN COMPONENT 'COAREA' OF STRUCTURE <fs_data> TO <fv_COAREA>.
 
           IF <fv_CCTR> IS NOT INITIAL.
             lv_CCTR = <fv_CCTR>.
           ENDIF.
           IF <fv_COAREA> IS NOT INITIAL.
             lv_COAREA = <fv_COAREA>.
           ENDIF.
         ENDLOOP.
*Fetch the email address of the requestor
        SELECT SINGLE smtp_addr
         FROM usr21 AS a INNER JOIN adr6 AS b ON a~persnumber =  b~persnumber
           AND a~addrnumber =  b~addrnumber
        INTO CORRESPONDING FIELDS OF ls_recipient
      WHERE bname EQ  ls_crequest-usmd_created_by.

  APPEND LS_recipient TO it_recepients.

*Prepare the subject of the mail
         iv_mail_subject = |CREATE COST CENTER MAIL|.
 
*Prepare the body of the mail
         DATA(cr_lf) = cl_abap_char_utilities=>cr_lf.
         DATA(iv_html_content) = |<html><head>| && cr_lf &&
 
         | <meta http-equiv="Content-Type" content="text/html; charset="uft-8">| && cr_lf &&
         | <title>{ iv_mail_subject }</title>| && cr_lf &&
         | <style TYPE="text/css">/* your CSS styles */</style>| && cr_lf &&
         | </head><body>| && cr_lf &&
         |Hi,<br><br>| && cr_lf &&
         |<br>| && cr_lf &&
         |Change request { ls_crequest-usmd_crequest } has been approved and Cost Center  { lv_cctr } is created .<br>| && cr_lf &&
         |<br>| && cr_lf &&
         |Kind Regards,<br>| && cr_lf &&
         |MDG Workflow | && cr_lf &&
         | </body></html>|.
  CONCATENATE iv_html_content lv_content INTO DATA(lv_body).

 **Sending an EMAIL.

CALL METHOD zcl_mdg_fi_utility=>send_email
                EXPORTING
                 it_recepients   = it_recepients
                 iv_mail_subject = iv_mail_subject
                 iv_html_content = iv_html_content
                 IMPORTING
                 et_message      = et_message.
       ENDIF.
       ENDCASE.
       ENDMETHOD.

 

 METHODS OF ZCL_FI_UTILITY :

5.png

                                            Fig 6 : Custom Utility Class Methods.

1.READ_CR_DETAIL :

 

METHOD read_cr_detail.
    DATA: lr_crequest TYPE REF TO if_usmd_crequest_api,
          lt_data     TYPE usmd_t_crequest_entity.


    CALL METHOD cl_usmd_crequest_api=>get_instance
      EXPORTING
        iv_crequest          = iv_cr_number
*       iv_model_name        = iv_model
      IMPORTING
        re_inst_crequest_api = lr_crequest.

    CALL METHOD lr_crequest->read_crequest
      IMPORTING
        es_crequest = es_crequest
        et_note     = es_note.

  ENDMETHOD.

 

2.READ_ENTITY_DATA :

 

METHOD read_entity_data.

    DATA:lt_entity TYPE usmd_t_entity,
         ls_entity TYPE usmd_s_entity.
    DATA:lv_entity TYPE usmd_fieldname.

    CALL METHOD cl_usmd_model_ext=>get_instance
      EXPORTING
        i_usmd_model = '0G'
      IMPORTING
        eo_instance  = DATA(lo_model).

    CHECK lo_model IS NOT INITIAL.
    IF iv_entity IS NOT INITIAL.
      lv_entity = iv_entity.
      ls_entity-usmd_entity = iv_entity.
      APPEND ls_entity TO lt_entity.
    ENDIF.

    IF iv_cr_number IS NOT INITIAL.

      lo_model->read_entity_data_all( EXPORTING i_fieldname = lv_entity
                                                if_active = ''
                                                i_crequest = iv_cr_number
                                                it_entity_filter = lt_entity
                                      IMPORTING et_data_entity = rt_data_entity ).
ENDIF.
  ENDMETHOD.

 

3.SEND_EMAIL :

 

METHOD send_email.
     DATA: lv_dummy.
      TRY.
 
        DATA(message) = NEW cl_bcs_message( ).
        message->set_subject( iv_mail_subject ).        "mail subject
 
         LOOP AT it_recepients INTO DATA(ls_recepients).
          message->add_recipient( ls_recepients-address ).   "List of recepients are added
          ENDLOOP.  
        message->set_main_doc(
          iv_contents_txt = iv_html_content
          iv_doctype = 'HTM' ).                              "Content of the mail

        message->send( ).                                    "mail is sent immediately

      CATCH cx_bcs_send INTO DATA(bcs_exception).

        DATA(error_text) = bcs_exception->get_text( ).
        MESSAGE e000(usmd5) WITH 'Error during sending E-mail notification:' error_text INTO lv_dummy.
        INSERT VALUE #( msgid = sy-msgid msgty = sy-msgty msgno = sy-msgno
        msgv1 = sy-msgv1 msgv2 = sy-msgv2
        msgv3 = sy-msgv3 msgv4 = sy-msgv4 ) INTO TABLE et_message.

    ENDTRY.
    ENDMETHOD.

 

 TRIGGERING THE CODE  IN BADI AFTER THE FINAL APPROVAL :

7.png

                                                              Fig 7 : System Method Caller BADI

VERIFYING THE EMAIL IN SOST ( t-code ) :

8.png

                                             Fig 8 : Email to the Recipient  

CONCLUSION :

                    In this way , this process can activate the Email Functionality & System will send a notification to the Requestor that Cost Centre has been Created in the System.

                           Your Ideas or suggestions about my blog are highly appreciated. Please feel free to post your comments below.

                        Also do  check out for other blogs which are related to MDG.

https://blogs.sap.com/2020/09/13/mdg-80-in-real-life-blog-series-how-to-configure-and-customize-rule... 

https://blogs.sap.com/2019/08/20/cross-entity-derivations-using-badi-usmdruleservicecrosset/ 

https://blogs.sap.com/2021/04/21/use-custom-filter-object-drff-in-the-s-4-hana-bp-outbound-replicati... 

https://blogs.sap.com/2018/10/02/mdg-configuration-of-the-screens-based-on-user-role/ 

Thanks!

                                 

 

 

 

saikatjay
Participant

Hello!! It's a good solution for triggering email notification and indeed a very detailed one.
You could make this into a framework by adding services to each step to trigger email notification for approval or reject actions.

Regards,
Saikat.

Accepted Solutions (0)

Answers (0)