- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:14 AM
Hi All,
I need to pass the instance name in the subject of the notification how this can be achieved ?can we do it in what it contains option or separate notification email script?
below is the existing notification email script for body
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:56 AM
you want email subject to contain instance name
then you need to use email.setSubject() in email script
(function runMailScript(current, template, email, email_action, event) {
var instancename1 = gs.getProperty("instance_name");
gs.log("testcountisstarting");
var event = new GlideRecord('sysevent');//new
event.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^stateNOT INprocessed,error,transferred^processedISEMPTY');
event.query();
if(event.next())
gs.log("ifevent");
var count = event.getRowCount();//new
gs.log("testcountis"+count);
//if (count >1000) {
if (count >= 1) {
var count2 = event.getRowCount();//new
email.setSubject("Instance name is" + instancename1);
//
template.print(instancename1+" "+ "event processing is stuck please check.The event count is"+" "+ count2);
}
})(current, template, email, email_action, event);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:15 AM
@Ankur Bawiskar any idea?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:56 AM
you want email subject to contain instance name
then you need to use email.setSubject() in email script
(function runMailScript(current, template, email, email_action, event) {
var instancename1 = gs.getProperty("instance_name");
gs.log("testcountisstarting");
var event = new GlideRecord('sysevent');//new
event.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^stateNOT INprocessed,error,transferred^processedISEMPTY');
event.query();
if(event.next())
gs.log("ifevent");
var count = event.getRowCount();//new
gs.log("testcountis"+count);
//if (count >1000) {
if (count >= 1) {
var count2 = event.getRowCount();//new
email.setSubject("Instance name is" + instancename1);
//
template.print(instancename1+" "+ "event processing is stuck please check.The event count is"+" "+ count2);
}
})(current, template, email, email_action, event);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:20 AM
HI @jobin1 ,
I trust you are doing fine.
To pass the instance name in the subject of the notification, you can modify the existing notification email script as follows:
(function runMailScript(current, template, email, email_action, event) {
var instancename1 = gs.getProperty("instance_name");
gs.log("testcountisstarting");
var event = new GlideRecord('sysevent');
event.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^stateNOT INprocessed,error,transferred^processedISEMPTY');
event.query();
if (event.next())
gs.log("ifevent");
var count = event.getRowCount();
gs.log("testcountis" + count);
if (count >= 1) {
var count2 = event.getRowCount();
var subject = instancename1 + " - Event Processing is Stuck";
var body = instancename1 + " event processing is stuck. Please check. The event count is " + count2;
template.print(body, subject);
}
})(current, template, email, email_action, event);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:28 AM - edited 06-16-2023 03:31 AM
thanks for the updates but not working ,i think subject cant be print in that way