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

hugogomes
Giga Expert

Hi

 

one way of doing this is, in the workflow trigger an event, and then in the notification define it to be sent on the event trigger.
You can pass the information in the {event.parm2}

 

if you want, to format the information you can "build" the HTML code to be passed to the {event.parm2}.

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

 

Here we will have to create a mail script and then call that mail script into notification.

In mail script you will have to write below code.

var arr = [];

var gr = new GlideRecord('sysapproval_approver');

gr.addQuery('sysapproval',current.sys_id);

gr.addQuery('state','requested');

gr.query();

while(gr.query())

{

arr.push(gr.approver);

}

 

template.print('Name and Email Id of remaining approvers');

for(var i=0;i<arr.length;i++)

{

var usr = new GlideRecord('sys_user');

usr.addQuery('sys_id',arr[i]);

usr.query();

if(usr.next())

{

template.print(usr.first_name+' '+usr.last_name+' - '+usr.email);

}

 

Call this mail script in notification as : ${mail_script:script name}

 

Note: This is sample code, please test it properly.

 

Thanks,
Ashutosh Munot

 

 

 

This doesn't seem to work. I set it up as described but only get the "Name and Email Id of remaining approvers" in the notification but no list of actual names or emails.

HI,

 

Show mw how you did it?

 

Thanks,

Ashutosh Munot