Push array from scheduled job into mail script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 07:43 AM
Hi Experts,
I have the following scheduled job script. Essentially, it will check records that are about to expire and send an email to the owner of the record. What I'm trying to do is when there are multiple records belonging to one person, I want to send them a list of the records.
I'm using an array to collect the names of the users but I dont know how to push that into an email notification script. I'm stuck so any help at is greatly appreciated!! :). Here is the scheduled job;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 07:52 AM
In your mail script, you can access event.parm1 and event.parm2 to get the information you pass to the event triggering the notification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 07:54 AM
Hi @Richard Thomas2,
Try this updated scripts -
ar processedAuthors = []; // Initialize an array to track processed authors
var gr = new GlideRecord('dms_document_revision');
gr.addEncodedQuery('xxxxxxxxxxx'); // Consider only active records, adjust as needed
gr.query();
while (gr.next()) {
processedAuthors.push(gr.author.getDisplayValue());
//if (processedAuthors.indexOf(author) === -1) {
gs.eventQueue('reminder', gr, processedAuthors.toString, gr.name);
//processedAuthors.push(author); // Add author to processed authors array
}
Email scripts -
event.parm1.toString();
If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 08:37 AM
Hi @Richard Thomas2, If you want to send the list of records belonging to the same person, then you need to store that data in an array first. Can you try the below approach?
var processedAuthors = {};
var gr = new GlideRecord('dms_document_revision');
gr.addEncodedQuery('xxxxxxxxxxx');
gr.query();
while (gr.next()) {
var author = gr.author.toString();
if (!processedAuthors[author]) {
processedAuthors[author] = [];
}
processedAuthors[author].push(gr.name.toString());
}
var uniqueAuthors = Object.keys(processedAuthors);
var grUser = new GlideRecord('sys_user');
grUser.addQuery('name', 'IN', uniqueAuthors);
grUser.query();
while (grUser.next()) {
var author = grUser.name.toString();
var recordsList = processedAuthors[author].join(', ');
gs.eventQueue('reminder', grUser, recordsList, '');
}
Regards,
Sunil