How to pass instance name in notification subject dynamically

jobin1
Tera Expert

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 

(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
 
 
 
//
 
template.print(instancename1+" "+ "event processing is stuck please check.The event count is"+" "+ count2);
}
 
 
 
})(current, template, email, email_action, event);
1 ACCEPTED SOLUTION

@jobin1 

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);

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

View solution in original post

4 REPLIES 4

jobin1
Tera Expert

@Ankur Bawiskar any idea?

@jobin1 

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);

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

Amit Gujarathi
Giga Sage
Giga Sage

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



thanks for the updates but not working ,i think subject cant be print in that way