How to trigger notification, it contains multiple records?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 06:24 AM
Hi Team,
I have requirement on email notification.
Based on Requestor, we need to trigger notification for each quarter and should show multiple records. How can we achieve this requirement?
For example, when gliding the table with one "quarter" duration, the following records are displayed:
INC001234 - Requestor A
INC002345 - Requestor B
INC004567 - Requestor A
INC002367 - Requestor A
INC004523 - Requestor A
INC005678 - Requestor B
So, I want to send a notification to Requestor A like following way:
------------------------------------------------------
Hi Requestor A,
The following records for this Quarter:
INC001234
INC004567
INC002367
INC004523
Thanks,
Team
------------------------------------------------
Requestor B like following way:
------------------------------------------------------
Hi Requestor A,
The following records for this Quarter:
INC002345
INC005678
Thanks,
Team
------------------------------------------------
I tried the following way:
var gr = new GlideRecord('incident');
gr.addQuery('u_status','u_active');
gr.query();
if(gr.next()){
var creDate = gr.sys_created_on;
var expDate = gs.now();
var diff = gs.dateDiff(creDate,expDate,true);
if(diff>=7344000 && diff<=7776000) // I've taken 85 and 86 days records
{
gs.print(gr.u_number+ '- ' gr.u_requestor);
}
}
By this script, I'm getting out put like:
INC001234 - Requestor A
INC002345 - Requestor B
INC004567 - Requestor A
INC002367 - Requestor A
INC004523 - Requestor A
INC005678 - Requestor B
Now I need to send a notification to Requestors A & B. I know by using gs.eventQueue we can send notification. But, my query is how can we separate requestors records and how can we send the same.
Please suggest solution ASAP.
Thanks & Regards,
Prasanna Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 06:29 AM
Hi Prasanna,
You are on the right track. You only need one event per person though.
I recommend you first use a GlideRecord query to make a list of the recipients, then once you have that list, trigger a notification to each of those people, passing the user's sys_id as one of the parameters.
In the notification, use a notification script to get the list of incidents for that user.
Scripting for Email Notifications - ServiceNow Wiki
Email Notifications - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 07:36 AM
Hi Tomasi,
Thanks for solution and its helpfull, Could you please provide logic to under stand more

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 08:02 AM
Hi Radhi. I don't understand your request. I did provide you the logic. The initial script would look something like this. Keep in mind none of this is tested!
var au = new ArrayUtil();
var list = [];
var inc = new GlideRecord('incident');
inc.addQuery('active', true);
inc.query();
while (inc.next()) {
list.push(inc.getValue('u_requester'));
}
var shortList = au.unique(list);
for (var i = 0; i < shortList.length; i++) {
gs.eventQueue('incident.requester.list', null, shortList[i], ''); // trigger the event
}
Register the event incident.requester.list
Then set up your notification to respond to that. In the body of your message you call a script;
${mail_script:incident_requester_list}
The notification script record would create a script something like this:
var inc = new GlideRecord('incident');
inc.addQuery('u_requester', event.parm1);
inc.addQuery('active', true);
inc.query();
while (inc.next()) {
template.print(inc.number);
}
Scripting for Email Notifications - ServiceNow Wiki
Email Notifications - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2016 11:38 PM
Hi Tomasi,
I've written following code in schedule job:
var au = new ArrayUtil();
var list = [];
var gr = new GlideRecord('u_contingent_worker_on_board_form');
gr.addQuery('u_status','u_active');
gr.query();
while(gr.next()){
var creDate = gr.sys_created_on;
var expDate = gs.now();
var diff = gs.dateDiff(creDate,expDate,true);
if(diff>=6912000 && diff<=7776000){
//gs.print(gr.u_number +':'+ gr.u_requestor.name);
list.push(gr.getValue('u_requestor'));
}
}
var shortList = au.unique(list);
//gs.print(shortList);
for (var i = 0; i <=shortList.length; i++) {
//gs.print(i);
gs.eventQueue('cwr.rem.85days',null,shortList[i],''); // trigger the event
}
Here we got output like 19 Requestors and 26 records So, the below mail script should call 19 times and print their records.
IN Notification script:
var gr = new GlideRecord('u_contingent_worker_on_board_form');
gr.addQuery('u_status','u_active');
gr.addQuery('u_requestor',event.parm1);
gr.query();
while(gr.next()){
var creDate = gr.sys_created_on;
var expDate = gs.now();
var diff = gs.dateDiff(creDate,expDate,true);
if(diff>=6912000 && diff<=7776000){
template.print(gr.u_number);
}
}
But, only one person got notification with one ticket. This is correct. But, remaining 18 people should get notification with their records. It is not happened. Please suggest how can we modify code to get all the members should get notification.
Please suggest possible solutions. Please help on this requirement.
Thanks & Regards,
Prasanna Kumar