Workflow. Sending Emails

Workflow. Sending Emails

Note Explanation

In this post, I’ll try not to be boring and predictable.

I won’t be going through the usual step-by-step explanation of how great it is that you can generate and send an email in a workflow using a Send Mail step. You probably already know that.

See: Mail Transmission

Instead, I’ll present a use case involving an Activity step to generate and send an email to the intended recipient.

See: Activity

It's worth noting that what interests me here is not so much the email sending itself, but rather transforming the task text into HTML format.

Why complicate things, blogger?

The Activity step in a workflow is a versatile tool that can handle many tasks. One of them can certainly be sending an email, especially since the task text is already embedded in the step.

Considering that you can apply various conditions to the task text, a single task could generate different messages for the same recipient.

I wrote about using conditions in Activity tasks in the post Standard Options for Configuring Workflow Tasks.

In this note, I’ll try to explain how to add a bit of dynamism to standard task text by converting it into HTML format.

1. Creating a Workflow

For demonstration purposes, I’ll use a simple workflow without any triggering events, created using transaction SWDD, and I’ll add an Activity task to it.

To control this task, I’ll use a utility class.

See: ABAP Classes in Workflow
For an example of creating a utility class, refer to the post Finding a Task Processor in a Workflow (section #3: Creating a utility class)

2. Task Text

I’ll add the task text that will be sent to the recipient.

0:00
/0:26

3. Processing the Task Text

The algorithm for the class method in this case will roughly be:

  • Determine the step/task identifier (workitem ID) that contains the text to be sent
  • Retrieve the task text (you can use FM SWU_GET_TASK_TEXTLINES)
  • Add <HTML> and <BODY> tags around the task text
  • Generate the email using, for example, class CL_BCS
  • Remember to bind the container elements before execution
See: Definition of Binding

Testing. Iteration 1

Testing will be done in an unusual way:

  • I’ll run the workflow
  • Copy the relevant workitem ID that holds the task text and process it using the utility class method
  • The result should be an email, which I’ll check in SAP via transaction SOST
0:00
/0:35

Testing. Iteration 2

To make things more interesting, I’ll add a simple CSS style to the email body.

0:00
/1:20

Note: The email's appearance in transaction SOST may not match what you see in your actual email client. I strongly recommend testing how it looks in a real client.

Testing. Iteration 3

To confirm I’m not deceiving you—or myself—I’ll remove the HTML tag generation from the method code and check what gets created in SOST.

0:00
/0:41

Thank you for your attention. As always, you're amazing.


Yours, ignatov.