JavaScript in Mail Task


Have created a process which needs to send Emails. In this email, I need to format the text based on some variable i.e. I have tried to use if/else conditions using Javascript. But this is not working for me. My question is , can I java-script inside mail task body ? If not, then is there any other way of formatting the text .Here is what am trying to do inside the “html” attribute of Mail-task : -

Hello Solution Delivery Team

A new request has been submitted with the following details :-

Project Name: ${projectNm}

Please initiate the following tasks:-

Application Ids required:-

  • Gold
  • Platinum


I’m not entirely clear what you’re trying to do, but you can use variables to insert whatever simple html content you want. I think you could have the process set the content through conditional flows or script tasks and just have an html attribute with a value something like “${emailTop}<br><p>Constant content</p>${emailBody1}<p>More constant content</p>${emailBody2}<br>${emailFooter}”, with the variables also containing simple html, e.g. emailTop = “<h1>Hello!</h1>”.


Thanks @PHH for replying. What am trying to achieve is Format the text e.g. (as per your example ) I want ${emailBody2} to appear only if its NOT NULL i.e. something like

if(null != ${emailBody2} ) {
Email Body 2 is : ${emailBody2}

Hope , I clarified what exactly am looking for.

Thanks again.

You can use the JUEL expressions more fully, for example:
${ ! empty myVar1 ? myVar1 : "<p><i>Something else<i></p>" }

So if myVar1 is not null or the empty string, it gets output (containing html, if desired), otherwise something else is output.


Thanks Paul this works. Is there any way , I can use Java directly to do this if/else stuff in mail-task ?

No. An alternative could be to have a java service tasks that prepares this text in Java and stores it as a transient variable that’s referenced in the mail task.

Thanks @joram, Got it . :slight_smile: