Adding multiple approvers in workflow approval user activity?

micky09
Tera Contributor

I have written the below script to add various group managers as approver, created a variable as list collector named it as 'group_names' now all the group managers of the selected groups should be added as approver in the activity, but the issue happening is only first selected group manager is getting added as approver ?

answer = [];
// answer.push('id1');
// answer.push('id2');
var grp = current.variables.group_names.getDisplayValue();
var arraylist = grp.split(",");
for(var i=0;i<arraylist.length;i++)
{
gr = new GlideRecord ('sys_user_group');
gr.addQuery('name',arraylist[i]);
gr.query();
if(gr.next())
{
gs.log('mk'+i+''+arraylist[i]);
answer.push(gr.manager);
}
}

 

Any help will be appreciated.

9 REPLIES 9

Manas Kandekar
Kilo Guru

Hi,

Try

answer.push(gr.manager.toString());

 

If my answer helped you in any way, please then mark it correct and helpful.

Kind regards,
Manas

Michael Jones -
Giga Sage

Try this.

When you push values to an array, you need to use .getValue('value') otherwise you are pushing a pointer to the GlideRecord and not a value. 

 

answer = [];
// answer.push('id1');
// answer.push('id2');
var grp = current.variables.group_names.getDisplayValue();
var arraylist = grp.split(",");
for(var i=0;i<arraylist.length;i++)
{
gr = new GlideRecord ('sys_user_group');
gr.addQuery('name',arraylist[i]);
gr.query();
if(gr.next())
{
gs.log('mk'+i+''+arraylist[i]);
answer.push(gr.getValue('manager'));
}
}
I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Thanks for the reply!

Tried the same still no luck it is still adding the approval manager only for the first selected group.

Jagadeesh1
Kilo Guru

Hello,

 

        Update the line to answer.push(gr.manager+'');

 

Thanks,

Jagadeesh