- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 04:42 AM
Hi everyone,
I want to change the subject of the notification according to the instance from which it's being triggered. Like if its a request creation notification:
normal notification: Request REQ0010286 was created
I want if it is being triggered from a test instance it is to be:
TEST Instance Notification Request REQ0010286 was created
if it is being triggered from the dev instance it is to be:
DEV Instance Notification Request REQ0010286 was created
I cannot edit every notification as there are more than 80
please help
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 05:17 AM - edited 10-12-2022 05:18 AM
BR would be before, on insert, for the sys_email table, with code as follows:
var environmentPrefix= '';
var instanceName= gs.getProperty('instance_name');
switch (instanceName) {
case 'sntest' : environmentPrefix = 'TEST '; break; //replace with your test instance name
case 'yourdev' : environmentPrefix = 'DEV '; break; //replace with your devinstance name
}
var oldSubject = current.subject + '';
current.subject = (environmentPrefix + oldSubject);
This is just an example (not tested) so give it a go.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 04:53 AM
If you are using common templates or layouts amongst your notifications, you could add a mail script in them to change the subject. Code would be something like below:
var environmentPrefix= '';
var instanceName= gs.getProperty('instance_name');
switch (instanceName) {
case 'sntest' : environmentPrefix = 'TEST '; //replace with your test instance name
case 'yourdev' : environmentPrefix = 'DEV '; //replace with your devinstance name
}
email.setSubject(environmentPrefix + email_action.subject);
Failing that, you would need to create a business rule on the sys_email table to change the subject when it is created. You could use similar code to above.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 05:02 AM
can you help me out abit more and write BR script for it. Sorry for the inconvenience

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 05:17 AM - edited 10-12-2022 05:18 AM
BR would be before, on insert, for the sys_email table, with code as follows:
var environmentPrefix= '';
var instanceName= gs.getProperty('instance_name');
switch (instanceName) {
case 'sntest' : environmentPrefix = 'TEST '; break; //replace with your test instance name
case 'yourdev' : environmentPrefix = 'DEV '; break; //replace with your devinstance name
}
var oldSubject = current.subject + '';
current.subject = (environmentPrefix + oldSubject);
This is just an example (not tested) so give it a go.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 05:24 AM
hello,
Is the notification already created and is on sc_request then do the below:-
Go to notification script
Write the below code
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var instance= gs.getProperty('instance_name');
var name;
if(instance.indexOf("dev")>-1)
{
name ='DEV';
}
else if(instance.indexOf("test")>-1)
{
name ='TEST';
}
else
{
name ='PROD';
}
email.setSubject(name+'Instance Request' +current.number +'was created');
})(current, template, email, email_action, event);
Then in the notification call it as below:-
Please mark my answer as correct based on Impact.