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

 

find_real_file.png

Did you try by adding some logs? Also confirm the group name app_SN_Role-VIP is correct.

 

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', 'app_SN_Role-VIP');

 

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.

Please find the workflow above

 

sujalavemula
Kilo Guru

you need to access variable of the catalog item and get the value of it first ,then you can check if the returned user is a member of that group.


access approvers name using current.variable_name.isMemberOf('group name');