Skip approval check if user is in a certain group (Service Catalog)

Mort
Kilo Contributor

Hello, In the catalog workflow I am trying to add a "check" (if statement) in our hardware and software workflow in which users in a certain group are pre-approved and skip the approval piece in the workflow. Here is what I have so far:

(I am not a developer so if this code is incorrect please let me know)

answer = preapprovalcheck();

function preapprovalcheck(){

var userCheck;

if(userCheck.isMemberOf('SN-ApprovedEAs')){

  answer = true;

  } else {

  answer = false;

  }

}

Here is the workflow:

find_real_file.png

1 ACCEPTED SOLUTION

Lets add some debugging. Let me know, what you see in system log after running the below script.



answer=preapprovalcheck();


function preapprovalcheck(){


gs.log('++++++++++++++++++current.requested_for is '+current.requested_for);


var grMem = new GlideRecord('sys_user_grmember');


grMem.addQuery('user', current.requested_for);


grMem.addQuery('group.name', 'SN-ApprovedEAs ');


grMem.query();


if(grMem.next()){


  return 'yes';


gs.log('++++++++++++++++In Yes++++++++++++++++++++');


  } else {


gs.log('++++++++++++++++In No++++++++++++++++++++');


  return 'no';


  }



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

14 REPLIES 14

amlanpal
Kilo Sage

Hi MKhan,



I believe you want to cross check that whether the user, who has raised the request is a member of the particular group or not. If so, please find the below script:



answer = preapprovalcheck();



function preapprovalcheck(){


var grMem = new GlideRecord('sys_user_grmember');  


grMem.addQuery('user', current.request.requested_for);  


grMem.addQuery('group.name', 'SN-ApprovedEAs ');  


grMem.query();  


if(grMem.next()){


  return 'yes';


  } else {


  return 'no';


  }



I hope this helps.Please mark correct/helpful based on impact


Mort
Kilo Contributor

Hi Amlan,



I have tried this solution but it looks like the pre-approval check is entirely skipped and the request goes to the next task after the approval. I have tested this with users in the pre-approved group and users not in the pre-approved group. Both requests automatically get approved. I used the exact script you posted above.


Try this. Since this is an approval workflow, it will be on the request table.



answer = preapprovalcheck();



function preapprovalcheck(){


var grMem = new GlideRecord('sys_user_grmember');


grMem.addQuery('user', current.requested_for);


grMem.addQuery('group.name', 'SN-ApprovedEAs ');


grMem.query();


if(grMem.next()){


  return 'yes';


  } else {


  return 'no';


  }



Please mark this response as correct or helpful if it assisted you with your question.

Mort
Kilo Contributor

Thanks Sanjiv, I have tried this but it is still not working. Every time I submit a catalog request from a user who is NOT in the approved group the request still skips the approval. I don't think it is doing the approval check at all and just approving all users.