How to remove potential member of approval group(s) if equal to requested_by within group approval workflow activity?

Zod
Giga Guru

Hi all,

I have a workflow scratchpad variable within an approval on sc_req_item .... and need to remove a potential group approver in case he/she is equal to the requested_by to avoid approving own requests.

Coud someone please help out here? The scratchpad might contain more than one approval group and I need to keep the group approval. Just pushing all approval users to the answer would not be sufficient. 

Best would even be that the user remains part of the approval group but his/her approval will automatically changed to "not required anymore".

Thnank you!!

 

find_real_file.png

1 ACCEPTED SOLUTION

OK. 

More easy with a Business Rule.

 

Table: sysapproval_approver

before / Insert

condition:

sysapproval.openey_bySAMEapprover^stateCHANGESTOrequested

 

Scipt: 

current.state = 'not_required';

current.comments = ''approval canceled because ....";

 

Just to make sure, that in case only one approver the whole approval might be approved if set to not required anymore ... 

 

 

View solution in original post

3 REPLIES 3

James Gragston
Tera Guru

Zod,

In the below example, your 'group approver' is my 'approver' so just substitute these values:

answer = [];

//'current' object is RITM record for this code
var requester = current.request.opened_by;

//grabing user input - you may be getting your approver a different way
var approver = current.variables.ITRP_OG_Approv;

var approvalGroup = workflow.scratchpad.my_approval_group;

if (approver != requester) {

    //if they aren't the same, send approvals to all members
    answer.push(approvalGroup);
} else {

    //else, add each member to answer array excluding the requester
    var gr= new GlideRecord('sys_user_grmember');

    gr.addQuery('group', approvalGroup);

    gr.addQuery('user','!=', requestor);

    gr.query();

    while(gr.next()){

    answer.push(gr.getValue('user'));

}


 

I tested this code (minus the last 'else' statement) with a single approver activity ('Approval - User'). If the approver was the same as the requestor, it skipped the Approval activity and continued with the workflow. It should work the same with a group.

Hope this helped!

... thank you.

But this looks for me like this would push relevant approvers (separat users) to the answer. 

But I would nee the groups (that potentially should remove the requestor in case part of the group.

So again.

I have workflow.scratchpad_appval_groups ( is [groupA_sys, groupB_sys]).

Requestor is userA. 

If userA is part of groupA the answer shoud contain [groupA_sys, groupB_sys] but userA should be removed from this group for the purpose of this approval.

 

So maybe the solution is to be fixed somewhere else instead. I.e. a Business Rule saying in case I get a apprval item where I am the requestor - set approval to not required anymore ... 

Any idea?

OK. 

More easy with a Business Rule.

 

Table: sysapproval_approver

before / Insert

condition:

sysapproval.openey_bySAMEapprover^stateCHANGESTOrequested

 

Scipt: 

current.state = 'not_required';

current.comments = ''approval canceled because ....";

 

Just to make sure, that in case only one approver the whole approval might be approved if set to not required anymore ...