Skip to Content
Technical Articles
Author's profile photo Gourab Dey

Understanding how email template works in Flexible Workflow

Introduction:

Today in this blog post, we will have a deep dive to understand how system uses email templates and how email is triggered by flexible workflow. There are many beautiful blog post available today on email template on flexible workflow, but the information on how system uses these template to trigger email is missing. So, we will discuss the same in this blog post.

Pre-requisite:

Knowledge of Flexible workflow and email template in Flexible Workflow is required. We won’t be discussing how flexible workflow works and how email template can be maintained to trigger email for flexible workflow. There are already so many beautiful blog post are available. Some of the links are given below. If you have not gone through the concept of flexible workflow and email template, then it is recommended to have a look into below links first then continuing this blog post

Los Geht’s:

A couple of points which are worth re-iterating:
  • The email template for Flexible Workflow is maintained using Fiori App “Maintain Email Template”.
  • The name of the email template should follow the below naming convension
    • YY1_<Scenario_ID>_CRT_<StepID> / YY1_<Scenario_ID>_CRT_ALL: Email template to be used when workitem is created
    • YY1_<Scenario_ID>_COMPLETE_POSITIVE: Email template to be used when workflow is approved (Point to note: It will be triggered when the workflow is approved, and not the workitem)
    • YY1_<Scenario_ID>_COMPLETE_NEGATIVE: Email template to be used when workflow is rejected(Point to note: It will be triggered when the workflow is rejected)
So, whenever the email templates are maintained, it is stored in below tables
SMTG_TMPL_HDR Email Template Header
SMTG_TMPL_HDR_T Email Template Name and Description

(Email template defined in Maintain Email Template Fiori App)

(Email template stored in Table)

Point to note: We can see the table is a cross client table, so no need to transport the email template across client.

Now that email template has been maintained using the Fiori apps, various event like work item creation, workflow approval and rejection, system check for the respective template associated with the workflow and creates an entry in the table “SWW_WIREGISTER” on the respective event(WI Creation, Approval and rejection) if email template is maintain for those events.

Let’s have a look into table entry to have an idea how it’s looks.

(Registration of a Work Item)

We can notice below points in the table entries

  • Application type is OPM(Output Management)
  • Subcategory
    • 001 – Email on workitem creation
    • 003 – Email on workflow approved/rejected
  • Value: We can in value field the respective “Email template” and “use case” has been stored
  • Use cases: Use case is the events on which email needs to be sent.
    • useCase-mailToWorkitemRecipients
    • useCase-postiveWorkflowCompletion
    • useCase-negativeWorkflowCompletion

The class “CL_SWF_RUN_OM_SERVICE“(Workflow: Mail service via output management) is responsible for workitem registration.

%28CL_SWF_RUN_OM_SERVICE%29

(Class CL_SWF_RUN_OM_SERVICE)

We can see various important method available in the class, for example “REGISTER”  method, which saves the entry to “SWW_WIREGISTER” table and “GET_TEMPLATE_ID” gets the workflow email template. All the method name are self explanatory, so I am skipping the explanation of the functionality of these methods.

%28Constants%20in%20class%20CL_SWF_RUN_OM_SERVICE%29

(Constants in class CL_SWF_RUN_OM_SERVICE)

Let’s have a look, where and how the class “CL_SWF_RUN_OM_SERVICE” is used to registered the workitem to trigger the email.

Let’s have a look into the the class “CL_SWF_RUN_WIM_DIALOG“, which will be called when a dialog workitem is created. The class has a method “CREATE_VIA_WFM” which calls the register method of class “CL_SWF_RUN_OM_SERVICE” to save the entry in “SWW_WIREGISTER“.

%28Method%20CL_SWF_RUN_WIM_DIALOG%20-%20CREATE_VIA_WFM%20registering%20the%20workitem%20for%20email%29

(Method CL_SWF_RUN_WIM_DIALOG =>CREATE_VIA_WFM registering the workitem for email)

So, this how the entry will be created in the table “SWW_WIREGISTER” for workitem creation use cases. Similarly system has to register the workitem on Workflow completion. That will be called from “IF_SWF_FLEX_IFS_RUN_APPL_STEP~AFTER_COMPLETION_CALLBACK” of callback class of the respective Flexible workflow.

Below is the screenshot of call back classes of flexible workflow for PO.(T-code: SWDD_SCENARIO_DISP, WF Template: WS00800238)

So, we understood how system is storing the entry in “SWW_WIREGISTER”. Now, that the entry are available in the table, but email has not yet triggered. So, how the email is triggered?

There is a report program “RSWF_OUTPUT_MANAGEMENT” which runs as a batch job every 1 min, which reads the table “SWW_WIREGISTER” and triggers the email.

Below are the screenshot of the program RSWF_OUTPUT_MANAGEMENT. We can see on the line number 28, the method “EXECUTE_ACTION” is called on object “LO_INSTANCE” and LO_INSTANCE is a object of class “CL_SWF_RUN_JOB_OUTPUT_MGMNT“.

%28Report%20RSWF_OUTPUT_MANAGEMENT%29

(Report RSWF_OUTPUT_MANAGEMENT)

We can see the “EXECUTE_ACTION” method calls “SEND_MAIL_TO_RECIPIENTS” method.

(Source of CL_SWF_RUN_JOB_OUTPUT_MGMNT->EXECUTE_ACTIONS)

“Vallah!!!” We can see the “EXECUTE_ACTIONS” uses the method “SEND_COMPLETION_MAILS” of class “CL_SWF_RUN_OM_SERVICE. The method SEND_MAIL_TO_RECIPIENTS reads the table “SWW_WIREGISTER” and sends the email to the recipient using email template.

(Overview of process)

Conclusion:

So, in this blog post we saw how work item is registered in table “SWW_WIREGISTER” using the class “CL_SWF_RUN_OM_SERVICE” during the Workitem creation, workflow approval or rejection, based on the availability of the email template. We also saw how the report program “RSWF_OUTPUT_MANAGEMENT” uses the same class “CL_SWF_RUN_OM_SERVICE” to send email. So, we had a complete picture how system handles email template on various events like workitem creation, workflow approval and rejection.

Hope this helps!

Assigned Tags

      13 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Ravi Prasad G
      Ravi Prasad G

      This is a brilliant blog which gives details on how email notification is sent when flexible workflow is triggered. Especially the report program RSWF_OUTPUT_MANAGEMENT is what i was looking for and i had been searching this for weeks.

      Not sure if SAP has documented the usage of this report program to trigger email in any of their SAP notes.

      Thanks so much Gourab for this blog and you saved me the efforts for writing custom logic to send emails for flexible workflows.

      Thanks once again.

       

      Author's profile photo Gourab Dey
      Gourab Dey
      Blog Post Author

      Hi Ravi,

      I am glad that this blog post helped you. And I thank you for your nice words.

      Author's profile photo Zhengzhang Lu
      Zhengzhang Lu

      Thanks for sharing the information! We now have some ideas on how to debug the things when the email not triggered as expected,

      Author's profile photo Gourab Dey
      Gourab Dey
      Blog Post Author

      Hi Zhengzhang,

      Yes, that exactly the motive was, to share info which can help on troubleshooting. I am glad it helped you.

      Thanks,

      Gourab

      Author's profile photo Suman Pradhan
      Suman Pradhan

      Hi Gourab,

      Thank you the detailed infromation . The blog clearly describes the steps involved to trigger a email  .

       

      I am working on a custom flexible workflow scenario in S4 HANA 2020 version ,and was wondering if there is a way to send attachments via email in the above method .

      Would you be able to shed any light on it?

      Thanks

      Suman Kalyan Pradhan

      Author's profile photo Gourab Dey
      Gourab Dey
      Blog Post Author

      Hi Suman,

      not sure if we can send the attachment.

      Thanks,

      Gourab

       

      Author's profile photo Dan Brooks
      Dan Brooks

      This is very useful.

      How do we transport the Z version of the templates across into QA and Prod?

      No transport was created when I created them. It doe not seem possible to manaully do this activity in QA/Prod anyway.

      Author's profile photo Gourab Dey
      Gourab Dey
      Blog Post Author

      Hi Dan,

      Below note describes the process. Hope it helps.

      https://launchpad.support.sap.com/#/notes/3170438

      Thanks,
      Gourab

      Author's profile photo Dan Brooks
      Dan Brooks

      Excellent, thanks very much for the help.

      Author's profile photo Arun Prema Venkatesh
      Arun Prema Venkatesh

      Hi Gourab,

       

      Thanks for the informative blog which was really needed to understand.

       

      I am creating custom flexible workflow and wanted to use email templates functionality.

      After creating the templates in Manage Email Template App, Do I need to write a code in callback class IF_SWF_FLEX_IFS_RUN_APPL_STEP~AFTER_COMPLETION_CALLBACK to call Class  CL_SWF_RUN_OM_SERVICE for registering/storing  the entry in table “SWW_WIREGISTER” or not needed?

      If writing the code part is required, Could you please share the code for calling it in class which is will be very helpful.

      Thanks,

      Arun P V

       

      Author's profile photo Martin Unger
      Martin Unger

      Hi Gourab,

       

      outstanding blog post with information I could not find anywhere else! Thank you!

       

      I am now able to send emails for workflow items - a whole email per workflow item unfortunately.

       

      This functionality is obviously replacing report RSWUWFML2 for sending notifications for work items. Report RSWUWFML2 has the option of switching the "send granularity" between "one message per work item" and "collective message". For the Output Management workflow email it seems that only "one message per work item" is possible.

       

      Or is it possible to send a "collective message" this way (i.e. several SWW_WIREGISTER entries in a single email)? Is there a possible approach?

       

      Best regards

      Martin

      Author's profile photo Gianni Solomita
      Gianni Solomita

      Hi Martin

      Did you manage to find a solution for the functionality "collective message"?

      Author's profile photo Martin Unger
      Martin Unger

      Hi Gianni,

      unfortunately not yet.