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
02-13-2025 06:37 AM
check this link where I shared how to combine and send email, you can enhance it further
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 07:36 AM
Currently i am triggering via event. Is my scheduled job correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 08:07 AM
you can check the link shared where I have proposed solution. enhance it
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 02:29 AM
My script was working fine. For the 2nd notification, i kind off used the same script and it worked fine too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 02:44 AM
Glad to know.
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