Weekly notifications are triggering multiple times for each record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 05:17 AM
Hi Community,
I have 2 notifications. 1st notification i want to trigger weekly for the records created last week. In the notification email body, i have added link of those records which are created last week. I have a scheduled job which is executing weekly but for each record its generating multiple emails. I only want to trigger it once for all records.
Here is my scheduled job code:
var lastWeek = new GlideDateTime();
lastWeek.addDaysUTC(-7); // 7 days ago
var abc = new GlideRecord('xyz');
abc.addEncodedQuery('sys_created_onONLast week@javascript:gs.beginningOfLastWeek()@javascript:gs.endOfLastWeek()', lastWeek); /
abc.query();
var records = [];
while (abc.next()) {
records.push(abc.sys_id + "");
// Fire the event for each record created last week
//gs.eventQueue('x_roho_ewm_infor_0.po.records', abc, abc.sys_id, gs.getUserID());
}
if (records.length > 0) {
// You can choose to serialize the records array or send it as a string
var recordsStr = records.join(','); // Join the sys_ids with commas, for example
// Fire the event with all the records as a parameter
gs.eventQueue('x_roho_ewm_infor_0.po.records', null, recordsStr, gs.getUserID());
}
Today i have created the array and made some changes. When i tried to give random time there and tested it, the email didnt triggered and when i clicked on execute now. It triggered one time but how can i make sure that it will trigger only once every week for all the records at a time not per record per email.
2nd notification i have when po id is empty in the new records inserted/updated. I want to trigger the notification to a group. But this notification is also getting triggered multiple times for each record. I only want to trigger it once when a new records are inserted/updated and doesnt have any po id. Users can click on the link i have added in email id for those records which doesnt have any po id. I dont have any scheduled job for this.
Need help here any suggestions.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 07:24 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader