Prefix Subject of Certain Email Notifications only if Service = 'ABC'

Leon Els
Tera Expert

Greetings friends,
I have a new requirement to Prefix email Notifications if Service = 'ABC', then the email subject should start with 'ABC - '.
Ideally, I would prefer not creating duplicate email notifications just for this Service and was hoping to use a script if possible.
Already consulted ChatGPT/CoPilot, could not get their recommended solutions to work.
Thanks in advance for any guidance.

Happy 2025 in advance!

2 ACCEPTED SOLUTIONS

@Leon Els 

use this in the IF condition

if(current.business_service.toString() == 'Give Your Exact Business Service Name Here')

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

Hi @Leon Els ,

 

Your text is incorrect, let me give you text.

 if (current.business_service && current.getDisplayValue('business_service') == 'SAP Enterprise Services') {
        // Prefix the subject with 'ABC - '
       
		email.setSubject('ABC - Incident ' + current.number + 'has been created - '+ current.short_description);

        // if getSubject() wont work then simply type your subject 
    }else{
		email.setSubject('Incident - ' + current.number + 'has been created - '+ current.short_description);
	}

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

18 REPLIES 18

Ankur Bawiskar
Tera Patron
Tera Patron

@Leon Els

since it requires dynamic subject you should use email script and set the subject

I hope you are aware on how to include email script in notification and you will be able to apply the correct condition in script

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

    // Add your code here

    if (current.service == 'ABC') { // give your correct condition here
        email.setSubject("ABC - " + 'Your Actual subject here');
    } else {
        email.setSubject('Your Actual subject here');
    }

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

I created my mail script and included the below in the subject of my email (this did not work) and then I tried to add the below to the body of my email, but this also did not work. 
Where should I add the code below in my notification, please?
Thank you!

${mail_script:Prefix_Email_Subject_By_Service_ABC} 

@Leon Els 

the way you included is correct.

you can include it at any place in notification body

As mentioned earlier ensure you give the correct condition based on the field which are you referring in your question i.e. Service and the correct value to compare i.e. ABC

Please share your latest email script and the notification is on which table and the field service which you are comparing and the value you are comparing

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thank you @Ankur Bawiskar 
This is on the incident table.

LeonEls_0-1735646577882.pngLeonEls_1-1735646677654.png