Sending out Workflow Emails

Workflow Emails

When the standard FAB workflow engine is used in an application, there is often a requirement to send emails to participants of the workflow to alert them of pending approvals, rejections or other details relating to the process.

The appropriate method to achieve this functionality is through the redefinition of the CHECK_AND_SEND_NOTIFICATION method in your Implementation Class.

Below is an example on how to send an email in this method using the SEND_MAIL method in the class /IQX/CL_FORMS_ASSIST.


    DATA: lv_sendemail TYPE xfeld.

    CALL METHOD super->check_and_send_notification
      EXPORTING
        i_form_name        = i_form_name
        i_instance         = i_instance
        i_current_status   = i_current_status
        i_action           = i_action
      IMPORTING
        e_email_to_be_sent = lv_sendemail.

    IF lv_sendemail = 'X'.

      CALL METHOD /iqx/cl_forms_assist=>send_mail
        EXPORTING
          p_from      = 'charles.evans@iqxbusiness.com'
          p_to        = lv_email     "<-- This would be the To address for the email
          p_subject   = lv_subject   "<-- This would be the subject for the email
          p_message   = lv_message   "<-- This would be the email body.  HTML is supported
          p_commit    = 'X'
          i_form_name = i_form_name  "<-- This can be passed in directly from the parameters in the method
          i_instance  = i_instance   "<-- This can be passed in directly from the parameters in the method
        CHANGING
          p_retcode   = lv_retcode.  "<-- Use this to determine if the email was queued successfully

    ENDIF.


In order for this sample to work, the variables in the send_mail call would need to be defined and assigned with the necessary data.  Emails can either be sent to each approver by looping through the IT_APPROVERS parameter, or each email address can be separated with semi-colons and then only one email needs to be set.

The call to the base class (CALL METHOD super->check_and_send_notification) will check the workflow configuration tables and return a true (X) or false ( ) depending on whether the Email Required checkbox is checked.  Please refer to the following diagram showing the Email Required field.  This can be used to turn email sending on and off for different status changes in the workflow configuration without the need to make code changes during any debugging.