cancel
Showing results for 
Search instead for 
Did you mean: 

SAP File Lifecycle Management - How can I trigger email notification when a user sends a file to next approver

0 Kudos

Is it possible to send email notification to an approver that a new file has come into his inbox? Similarly, can we send email notification to a substitute?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

You can send notifications as message through SAP Business Workplace (SBWP).

• Sending email notification to substitute –

o Maintain Customizing settings – Maintain the settings required in SPRO under  SAP Customizing Implementation Guide -> SAP NetWeaver -> Application Server -> SAP File Lifecycle Management -> Correspondence

o Create a Z service - You need to create a Z Service redefining the standard service /PSINDS/FILES_SRV and the redefine it by adding the Mail Triggering code given below to the standard code.

o Note  you should add the Mail Triggering code in that section of the  Execute Action method where condition for adding the substitute is handled

Mail triggering code

Create a Function Module 'ZFLM_SUBST_MAIL’ with below code. This function module accepts the content , agent and the dates to generate and send the mail notification

function zflm_subst_mail.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(IV_AGENT) TYPE  SY-UNAME

*"     REFERENCE(IV_BDATE) TYPE  SY-DATUM

*"     REFERENCE(IV_EDATE) TYPE  SY-DATUM

*"     REFERENCE(IV_REASON) TYPE  /PSINDS/SBUREASTXT

*"----------------------------------------------------------------------

  types:

  begin of  ty_rec,

    email type ad_smtpadr,

    name type string ,

  end of ty_rec .

  types:

  tt_rec type table of ty_rec .

  data : lv_sub type so_obj_des,

         lv_pernr type persno,

         lv_oid type char12,

         l_plvar type plvar,

         lt_result_tab type tswhactor,

         lt_result_objec type objec_t,

         lt_result_struc type struc_t,

         ls_result_objec type objec,

         lv_name type string,

         lv_id type string,

         lv_body type string,

         lv_bdate type sy-datum,

         lv_edate type sy-datum,

         lv_date type char2,

         lv_year type char4,

         lv_count type i,

         lv_month type char2,

         lv_from type string,

         lv_to type string,

         ls_docid type soodk,

         ls_folid type soodk,

         lv_agent type char14,

         lv_un type char12,

         lv_addr type bapiaddr3,

         lt_rec type tt_rec,

         lv_pos type plans,

         lv_slen type i,

         begin of ls_userdetails,

           orgtx type orgtx,

           ename type emnam,

         end of ls_userdetails,

         ls_rec like line of lt_rec,

         lit_return type table of bapiret2,

         lv_reason type /psinds/sbureastxt,

         lv_uname type sy-uname.

  lv_agent = iv_agent.

  lv_bdate = iv_bdate.

  lv_edate = iv_edate.

  lv_reason = iv_reason.

  call function 'RH_GET_ACTIVE_WF_PLVAR'

    exporting

      set_default_plvar = 'X'

    importing

      act_plvar         = l_plvar

    exceptions

      no_active_plvar   = 1

      others            = 2.

  lv_uname = cl_abap_syst=>get_user_name( ).

  lv_pernr = lv_uname.

  select single plans from pa0001 into lv_pos where pernr = lv_pernr and begda <= sy-datum and endda >= sy-datum.

  select single orgtx ename into corresponding fields of ls_userdetails from pa0001 as a join t527x as b on a~orgeh = b~orgeh where a~pernr = lv_pernr.

  lv_oid = lv_pos.

  call function 'RH_STRUC_GET'

    exporting

      act_otype    = 'S'

      act_objid    = lv_oid

      act_wegid    = 'WF_ORGUS'

      act_plvar    = l_plvar

    tables

      result_tab   = lt_result_tab

      result_objec = lt_result_objec

      result_struc = lt_result_struc.

  lv_name = ls_userdetails-ename.

  read table lt_result_objec into ls_result_objec with key otype = 'S'.

  concatenate lv_name ls_result_objec-stext ls_userdetails-orgtx into lv_name separated by '-'.

  lv_sub = 'FLM Substitution Alert'.

  lv_body = 'You have been substituted by'.

  concatenate lv_body lv_name 'From' into lv_name separated by ' '.

  lv_year = lv_bdate+0(4).

  lv_month = lv_bdate+4(2).

  lv_date = lv_bdate+6(2).

  concatenate lv_date lv_month lv_year into lv_from separated by '.'.

  lv_year = lv_edate+0(4).

  lv_month = lv_edate+4(2).

  lv_date = lv_edate+6(2).

  concatenate lv_date lv_month lv_year into lv_to separated by '.'.

  concatenate lv_name lv_from 'To' lv_to into lv_name separated by ' '.

  if lv_reason is not initial.

    concatenate lv_name '...Reason:' lv_reason into lv_name.

  endif.

  call method /psinds/cl_bl_mail=>save_mail_as_draft

    exporting

      iv_subject = lv_sub

      iv_body    = lv_name

*     iv_docid   =

    importing

      es_docid   = ls_docid

      es_folid   = ls_folid.

  lv_slen = strlen( lv_agent ).

  if lv_slen >= 3.

    lv_slen = lv_slen - 2.

    lv_un = lv_agent+2(lv_slen).

  endif.

  call function 'BAPI_USER_GET_DETAIL'

    exporting

      username = lv_un

    importing

      address  = lv_addr

    tables

      return   = lit_return.

  ls_rec-name = lv_addr-fullname.

  ls_rec-email = lv_un.

  append ls_rec to lt_rec.

  call method /psinds/cl_bl_mail=>/psinds/if_bl_mail~send_mail

    exporting

      it_rec     = lt_rec

      iv_subject = lv_sub

      it_content = lv_name.

endfunction.

Redefine the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION.

method /iwbep/if_mgw_appl_srv_runtime~execute_action.

    data : ls_param1 type /iwbep/s_mgw_name_value_pair,

        ls_msg type bapiret2,

        ls_param2 type /iwbep/s_mgw_name_value_pair,

        ls_param3 type /iwbep/s_mgw_name_value_pair,

        ls_param4 type /iwbep/s_mgw_name_value_pair,

        ls_param5 type /iwbep/s_mgw_name_value_pair,

        ls_param6 type /iwbep/s_mgw_name_value_pair,

        ls_param7 type /iwbep/s_mgw_name_value_pair,

        lv_msg type bapiret2-message,

        wa_es_data type /psinds/cl_files_srv_mpc=>ts_fi_response_et,

        lt_msg type bapiret2_t,

        lv_agent type sy-uname,

        lv_bdate type sy-datum,

        lv_edate type sy-datum,

              lv_reason type /psinds/sbureastxt,

        ls_subst type /psinds/cl_files_srv_mpc=>ts_file_subst_op_et.

               

  read table it_parameter into ls_param1 with key name = 'param_1'.

  read table it_parameter into ls_param2 with key name = 'param_2'.

  read table it_parameter into ls_param3 with key name = 'param_3'.

  read table it_parameter into ls_param4 with key name = 'param_4'.

  read table it_parameter into ls_param5 with key name = 'param_5'.

  read table it_parameter into ls_param6 with key name = 'param_6'.

  read table it_parameter into ls_param7 with key name = 'param_7'.

  field-symbols : <fs_et_data> type standard table,

                 <fs_sr_data> type standard table,

                 <fs_dc_data> type standard table.

  case iv_action_name.

    when 'FILES_FI'.

      create data er_data type table of /psinds/cl_files_srv_mpc=>ts_fi_response_et.

      assign er_data->* to <fs_et_data>.

      if ls_param1-value = 'AC'.

        ls_subst-otype = 'US'.

        ls_subst-objid = ls_param2-value.

        ls_subst-date_begin = ls_param3-value.

        ls_subst-date_end = ls_param4-value.

        ls_subst-reason = ls_param5-value.

        call method /psinds/cl_helper_file=>personnel_setting_options

          exporting

            iv_option       = 'AC'

            is_subst        = ls_subst

          importing

            ct_msg          = lt_msg

            ev_subst_status = wa_es_data-add_info.

        read table lt_msg into ls_msg with key type = 'E'.

        if sy-subrc = 0.

          clear wa_es_data.

          wa_es_data-msg_id = ls_msg-number.

          wa_es_data-msg_type = 'E'.

          call function 'BAPI_MESSAGE_GETDETAIL'

            exporting

              id         = ls_msg-id

              number     = ls_msg-number

              textformat = 'HTM'

            importing

              message    = lv_msg.

          wa_es_data-msg_text = lv_msg.

        else.

          lv_agent = ls_subst-objid.

          lv_bdate = ls_subst-date_begin.

          lv_edate = ls_subst-date_end.

          lv_reason = ls_subst-reason.

          call function 'ZFLM_SUBST_MAIL'

            exporting

              iv_agent  = lv_agent

              iv_bdate  = lv_bdate

              iv_edate  = lv_edate

              iv_reason = lv_reason.

        endif.

        append wa_es_data to <fs_et_data>.

      elseif ls_param1-value = 'AS'.

        if ls_param6-value = 'X'.

          ls_subst-otype = 'US'.

          ls_subst-objid = ls_param2-value.

          ls_subst-date_begin = ls_param3-value.

          ls_subst-date_end = ls_param4-value.

          ls_subst-profile = ls_param5-value.

          ls_subst-active = ls_param6-value.

          ls_subst-reason = ls_param7-value.

          call method /psinds/cl_helper_file=>personnel_setting_options

            exporting

              iv_option       = 'AS'

              is_subst        = ls_subst

            importing  

              ct_msg          = lt_msg

              ev_subst_status = wa_es_data-add_info.

          read table lt_msg into ls_msg with key type = 'E'.

          if sy-subrc = 0.

            clear wa_es_data.

            wa_es_data-msg_id = ls_msg-number.

            wa_es_data-msg_type = 'E'.

            call function 'BAPI_MESSAGE_GETDETAIL'

              exporting

                id         = ls_msg-id

                number     = ls_msg-number

                textformat = 'HTM'

              importing

                message    = lv_msg.

            wa_es_data-msg_text = lv_msg.

          else.

            lv_agent = ls_subst-objid.

            lv_bdate = ls_subst-date_begin.

            lv_edate = ls_subst-date_end.

            lv_reason = ls_subst-reason.

            call function 'ZFLM_SUBST_MAIL'

              exporting

                iv_agent  = lv_agent

                iv_bdate  = lv_bdate

                iv_edate  = lv_edate

                iv_reason = lv_reason.

          endif.

          append wa_es_data to <fs_et_data>.

        else.

          try.

              call method super->/iwbep/if_mgw_appl_srv_runtime~execute_action

                exporting

                  iv_action_name          = iv_action_name

                  it_parameter            = it_parameter

                  io_tech_request_context = io_tech_request_context

                importing

                  er_data                 = er_data.

            catch /iwbep/cx_mgw_busi_exception .

            catch /iwbep/cx_mgw_tech_exception .

          endtry.

        endif.

      else.

        try.

            call method super->/iwbep/if_mgw_appl_srv_runtime~execute_action

              exporting

                iv_action_name          = iv_action_name

                it_parameter            = it_parameter

                io_tech_request_context = io_tech_request_context

              importing

                er_data                 = er_data.

          catch /iwbep/cx_mgw_busi_exception .

          catch /iwbep/cx_mgw_tech_exception .

        endtry.

      endif.

when others.

      try.

          call method super->/iwbep/if_mgw_appl_srv_runtime~execute_action

            exporting

              iv_action_name          = iv_action_name

              it_parameter            = it_parameter

              io_tech_request_context = io_tech_request_context

            importing

              er_data                 = er_data.

        catch /iwbep/cx_mgw_busi_exception .

        catch /iwbep/cx_mgw_tech_exception .

      endtry. 

endcase.

endmethod.

• Sending email notification to next approver

o Maintain Customizing settings – Maintain the settings required in SPRO under  SAP Customizing Implementation Guide -> SAP NetWeaver -> Application Server -> SAP File Lifecycle Management -> Correspondence

o Create a Z service - You need to create a Z Service redefining the standard service /PSINDS/FILES_SRV and the redefine it by adding the Mail Triggering code given below to the standard code.

o Note  you should add the Mail Triggering code in that section of the  Execute Action method where condition for sending the file is handled

o Add the Mail triggering code mentioned above