Workflow - Group Approval Advanced Script

Andrii
Kilo Guru

What I want to achieve: there are 10 groups of 2 people. I need to get at least one approval from each group. If a user is the member of several groups - he needs to approve several times.

If I add "Group Approval" activity and select these 10 groups in "Group" field - everything works as I want. If "Abel Tuter" is the member of 10 groups - there will be 10 approval records for Abel Tuter t approve/reject.

However if I select Advanced and try to query these groups - approvals are not created for most of members. Actualy I get only 1 approval record. Is there something I miss?

var answer = [];

var ApprovalGroup = 'a509e63e4f6ef200ff5fafdd0210c79c';

var gr = new GlideRecord('sys_user_group');

gr.addQuery('type,ApprovalGroup);

gr.query();

while (gr.next()) {

answer.push(gr.sys_id);

}

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

I have had a lot of success with using a User approval. It may seem counter-intuitive, but you can add an array of groups to a user approval. It may actually do what you are expecting and have multiple approvals.



Also, when you do a push, use the toString() method:



answer.push(cab.sys_id.toString());


View solution in original post

4 REPLIES 4

ccajohnson
Kilo Sage

I have had a lot of success with using a User approval. It may seem counter-intuitive, but you can add an array of groups to a user approval. It may actually do what you are expecting and have multiple approvals.



Also, when you do a push, use the toString() method:



answer.push(cab.sys_id.toString());


Very interesting ...



After I added .toString() -   I get 1 approver from each group but not all approver - only 1 (I believe 1st one).



Seems that mechanism adds 1st available in alphabetic order


Oh, sorry - that was my fault. Another user was locked. So, converting to string did the job. Thank you.


Dave Smith1
ServiceNow Employee
ServiceNow Employee

ANDRII IARMOLATII wrote:



What I want to achieve: there are 10 groups of 2 people. I need to get at least one approval from each group. If a user is the member of several groups - he needs to approve several times.


Two questions at this point:


  1. is this the right way about it? If I've already approved it, I'm not sure I'd like to be asked repeatedly for the same decision because I belong to several groups.
  2. what you're after is a user approval, rather than group approval - you want an individual from each group to give a decision, rather than all the members, it seems.