Expand my Community achievements bar.

SOLVED

Workflow email properties

Avatar

Level 2

I would like to customize the email template for workflow event notification to include the payload title. Is title exposed in some way to use in workflow emails? From the documentation I can see that the options available are ${payload.data}, ${payload.type}, ${payload.path} -- where can I pull back payload title?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @majohns0321 

 

You can retrieve the page title in the Workflow model and set it based on the custom template. Please see the code below:

 

Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("Time", Calendar.getInstance().getTime().toString());
valuesMap.put("Step", workItem.getNode().getTitle());
valuesMap.put("Workflow", workItem.getWorkflow().getWorkflowModel().getTitle());
valuesMap.put("Content", workItem.getWorkflowData().getPayload().toString()); // Here I am reading the content and printing on the email, same way you can read any property from payload and send it to template.
StrSubstitutor strSubstitutor = new StrSubstitutor(valuesMap);
HtmlEmail email = createEmail(template, strSubstitutor);
email.setTo(emailRecipients);
this.messageGatewayService.getGateway(HtmlEmail.class).send(email);

 

Now in template read like below:

 

<div style="font-family:Calibri;font-size:11.0pt">
-------------------------------------------------------------------------------------
Time: ${Time}
Step: ${Step}
Workflow: ${Workflow}
-------------------------------------------------------------------------------------
Content: ${Content}
-------------------------------------------------------------------------------------<br/>
This is an automatically generated message. Please do not reply.
</div>

 

Thanks!

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @majohns0321 

 

You can retrieve the page title in the Workflow model and set it based on the custom template. Please see the code below:

 

Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("Time", Calendar.getInstance().getTime().toString());
valuesMap.put("Step", workItem.getNode().getTitle());
valuesMap.put("Workflow", workItem.getWorkflow().getWorkflowModel().getTitle());
valuesMap.put("Content", workItem.getWorkflowData().getPayload().toString()); // Here I am reading the content and printing on the email, same way you can read any property from payload and send it to template.
StrSubstitutor strSubstitutor = new StrSubstitutor(valuesMap);
HtmlEmail email = createEmail(template, strSubstitutor);
email.setTo(emailRecipients);
this.messageGatewayService.getGateway(HtmlEmail.class).send(email);

 

Now in template read like below:

 

<div style="font-family:Calibri;font-size:11.0pt">
-------------------------------------------------------------------------------------
Time: ${Time}
Step: ${Step}
Workflow: ${Workflow}
-------------------------------------------------------------------------------------
Content: ${Content}
-------------------------------------------------------------------------------------<br/>
This is an automatically generated message. Please do not reply.
</div>

 

Thanks!