- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 03:13 AM - edited ‎12-31-2024 03:15 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 04:06 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 04:41 AM - edited ‎12-31-2024 04:43 AM
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
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 04:08 AM
Hi @Leon Els ,
Use below modified script, i have tested it working fine. Remove the subject from notification.
if (current.business_service && current.getDisplayValue('business_service') == 'SAP Enterprise Services') { // replace with your reference field name, i have used Service for incident
// Prefix the subject with 'ABC - '
email.setSubject('ABC - Runjay');
// if getSubject() wont work then simply type your subject
}else{
email.setSubject('Runjay');
}
-------------------------------------------------------------------------
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
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 04:24 AM - edited ‎12-31-2024 04:26 AM
Thank you, @Runjay Patel !
Been making good progress with your guidance of removing the subject from the email notification and now I get the Prefix in the email!
However, it appears to negatively impact the rest of my email subject: (see below, issue is the INC # is not getting parsed)
ABC - Incident 84KXwi61 has been Created - u9iq44HG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 04:26 AM
Hi @Leon Els ,
What impact? it should not have any impact, code will set the subject line. Let me know if need any further help on this?
-------------------------------------------------------------------------
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
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 04:34 AM
Please see two screenshots below, the text in red blocks are unexpected.
It should indicate my Incident Number and Short Description as indicated by the red arrows.
Thank you @Runjay Patel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 04:37 AM
you should use current.number and current.short_description to get the field values
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader