Push array from scheduled job into mail script

Richard Thomas2
Tera Contributor

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;

 

 

var 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.toString);
//if (processedAuthors.indexOf(author) === -1) {
gs.eventQueue('reminder', gr, processedAuthors.toString, gr.name);
//processedAuthors.push(author); // Add author to processed authors array
}
3 REPLIES 3

Kristen Ankeny
Kilo Sage

In your mail script, you can access event.parm1 and event.parm2 to get the information you pass to the event triggering the notification.

Sagar Pagar
Tera Patron

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

The world works with ServiceNow

SunilKumar_P
Giga Sage

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