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

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.

Mort
Kilo Contributor

For some reason this same script started working for me. Thanks!


I have used your script which you have mentioned but didn't work. Basically, I have one workflow where I'm checking whether requested user is belongs to VIP group or not. If that user from VIP group then workflow should skip all the approvals and should go directly to Fulfillment stage. How can I do this?

answer = preapprovalcheck();
function preapprovalcheck()
{
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';
} else {
return 'no';
}
}

Can you post the complete workflow?

 


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

find_real_file.png