Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Conditional Logic on Email Notifications

sseverance
Tera Contributor

For email notifications, is it possible to use conditional logic for what the email will contain? For instance, if the short description contains "application related request" then add another piece of information like the long description? 

5 REPLIES 5

joshuajacks
Kilo Sage

@sseverance 

Sure! Depending on what you're using to generate the notification, you can use a mail script:
https://www.servicenow.com/docs/r/platform-administration/c_ScriptingForEmailNotifications.html

 

Or if you're using the "send email" flow action, then you can specify the logic that creates the email body.

Ankur Bawiskar
Tera Patron

@sseverance 

yes this is feasible

you can use email script and use script there to add dynamic email body, even dynamic subject etc

Scripting for email notifications 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Bhargavi Patel
Kilo Guru

Hi @sseverance 

Yes. You can use Mail Scripts or Notification Email Scripts to add conditional logic to the email content.

if (current.short_description.indexOf("application related request") > -1) {
template.print(current.description);
}

This prints the long description only when the short description contains "application related request".


Please Accept the solution if it assisted you with your question & Mark this response as Helpful.

 

 

Tanushree Maiti
Tera Patron

Hi @sseverance 

 

You can easily add conditional logic to your email notifications using ServiceNow Email Scripts .

 This allows you to evaluate record data dynamically and print specific information—such as the long description—only when your conditions are met.

 

1.Create an Email Script:
Navigate to System Policy > Email > Notification Email Scripts >click New.

 

(function runMailScript(current, template, email, email_action, event) {

      var shortDesc = current.short_description.getDisplayValue();

    if (shortDesc.indexOf("application") > -1) {

         template.print("Additional Information: <br/>");

        template.print(current.description.getDisplayValue());

    }

})(current, template, email, email_action, event);

 

2.Add to Notification:
Open your target email notification. In the Message HTML body, call your script by typing

${mail_script:your_script_name}

 exactly where you want the conditional content to appear.

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti