Need a script to list members names and emails in a notification.

wade88761
Kilo Contributor

I'm looking for a script that will list out the members of an approval group and their emails that the current request is waiting for approval from. This is so the Requester will know who to contact if an approval is taking too long. The notification is being built in the actual workflow. Any help is appreciated.

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


Here you go:

 

Use this below mail script :

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

// Add your code here
gs.log('Sys Id '+current.sys_id,'Munot');
var arr = [];
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id',current.sys_id);
gr.addQuery('state','requested');
gr.query();
while(gr.next())
{

arr.push(gr.approver.toString());
}

template.print('arr'+arr);
var rows;
for(var i=0;i<arr.length;i++)
{
gs.log('User Id '+arr[i],'Munot');
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id',arr[i]);
usr.query();
if(usr.next())
{
gs.log('inIf','Munot');
rows += '<tr>';
rows += '<td>' + usr.first_name + '</td>';
rows += '<td>' + usr.email + '</td>';
rows +='</tr>';

}
}
var data;
data = '<table style="border-collapse: collapse;" border="1" cellpadding="5"><tbody>';
data += '<tr><th>Name</th><th>Email Id</th></tr>';
data += rows;
data += '</tbody></table>';
template.print(data);
})(current, template, email, email_action, event);

 

Results are as below:

find_real_file.png

Use this in notification:

${mail_script:remaining.approver} //remaining.approver is my mail script name

 

Thanks,
Ashutosh Munot

View solution in original post

7 REPLIES 7

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


Here you go:

 

Use this below mail script :

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

// Add your code here
gs.log('Sys Id '+current.sys_id,'Munot');
var arr = [];
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id',current.sys_id);
gr.addQuery('state','requested');
gr.query();
while(gr.next())
{

arr.push(gr.approver.toString());
}

template.print('arr'+arr);
var rows;
for(var i=0;i<arr.length;i++)
{
gs.log('User Id '+arr[i],'Munot');
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id',arr[i]);
usr.query();
if(usr.next())
{
gs.log('inIf','Munot');
rows += '<tr>';
rows += '<td>' + usr.first_name + '</td>';
rows += '<td>' + usr.email + '</td>';
rows +='</tr>';

}
}
var data;
data = '<table style="border-collapse: collapse;" border="1" cellpadding="5"><tbody>';
data += '<tr><th>Name</th><th>Email Id</th></tr>';
data += rows;
data += '</tbody></table>';
template.print(data);
})(current, template, email, email_action, event);

 

Results are as below:

find_real_file.png

Use this in notification:

${mail_script:remaining.approver} //remaining.approver is my mail script name

 

Thanks,
Ashutosh Munot

That works great, is there anyway to remove the user's sys_id's from displaying above the table?

Nevermind, figured it out. Thanks again!