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

Make CSM Email Notification Subject Line Dynamic

Mundo23
Tera Contributor

Does anyone know of a way to dynamically change the subject line of an auto email notification based on logic or conditions.  

 

Example:  Using the same email notification, with same sending trigger conditions or in the same flow/subflow, insert a subject line for one client, but a different subject line for a different client.  

 

 

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @Mundo23 

 

Use a Notification Email Script to evaluate conditions and override the subject line using email.setSubject().

Ref: Email Client Script Dynamically Changing Subject Line 

 

Step 1: Create the Notification Email Script

  • Navigate to System Policy > Email > Notification Email Scripts in your ServiceNow instance.
  • Click New.
  • Set the Name (like  set_dynamic_client_subject).
  • In the Script field, add your logic.

Sample code :

 

if (current.client == 'Client A') {

    email.setSubject("Important Update for Client A: " + current.number);

} else if (current.client == 'Client B') {

    email.setSubject("Important Update for Client B");

} else {

    email.setSubject("General Notification: " + current.short_description);

}

 

Step 2: Add the Script to your Notification

  • Open the Email Notification you want to send.
  • Call email script from within the body : ${mail_script:set_dynamic_client_subject}

 

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

View solution in original post

2 REPLIES 2

Tanushree Maiti
Tera Patron

Hi @Mundo23 

 

Use a Notification Email Script to evaluate conditions and override the subject line using email.setSubject().

Ref: Email Client Script Dynamically Changing Subject Line 

 

Step 1: Create the Notification Email Script

  • Navigate to System Policy > Email > Notification Email Scripts in your ServiceNow instance.
  • Click New.
  • Set the Name (like  set_dynamic_client_subject).
  • In the Script field, add your logic.

Sample code :

 

if (current.client == 'Client A') {

    email.setSubject("Important Update for Client A: " + current.number);

} else if (current.client == 'Client B') {

    email.setSubject("Important Update for Client B");

} else {

    email.setSubject("General Notification: " + current.short_description);

}

 

Step 2: Add the Script to your Notification

  • Open the Email Notification you want to send.
  • Call email script from within the body : ${mail_script:set_dynamic_client_subject}

 

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

@Tanushree Maiti 

Thank you!  This with slight modifications to reference the fields we needed, your suggestion worked perfectly.