How to trigger notification using events and scheduled job

abhaysingh98
Tera Contributor

Hello,

 

I have a requirement where I need to trigger a notification to opened by user on monthly basis. I have created a notification and used email script to print all the active tickets that are opened by user and now I want to trigger this notification to opened by users on first day of month so that they can track all their tickets status.

 

This is the conditional scheduled job I have created please let me know some changes so that it can only trigger to opened by user on monthly basis.

 

Condition -

function checkmonday() {
var gdt = new GlideDateTime();
var day = gdt.getDayOfWeek();
var result = false;
 if (day == 1 && gdt.getDayOfMonth()<=7){
  result = true;
  }
 return result;
}

checkmonday();
 
 
Script-
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
    gs.eventQueue('incident.opened_by', gr, gr.opened_by);
}
 
I want to know how can I send this notification to all the opened by user that have opened the tickets I don't want it to trigger for all the records opened by (it will send multiple notification if we trigger it for all the tickets)
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@abhaysingh98 

check this link where I shared solution and you can send 1 email per user and in that email print all the details

this will avoid sending multiple emails to same user

enhance it for your requirement

Email Notification to all users of assets assigned specifically to them 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar ,

 

I have used this script in scheduled job to trigger mail once for a user not for all records in which user is submitted_by.

 

Script -

var activityL = new GlideRecord('table_name');
activityL.groupBy("submitted_by");
activityL.query();
while (activityL.next()) {
    var activityL1 = new GlideRecord('table_name')
    activityL1.addQuery('submitted_by',activityL.submitted_by);
    activityL1.query();
    gs.eventQueue('event name', activityL1, activityL1.submitted_by);
}
 
I am able to get the users list by this script in background script but it is working in scheduled job.