Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

manager approval with evp condition

gayatri38
Giga Guru

Have created a field "evp" as reference type in sys choice and added 2 options yes/no. So, the requirement is, when user's manager has evp field is yes then ask for approval if not check for managers manager has evp field set to yes. i have written the code, but its not working?

 

var answer = [];
var evp='yes';
var managerevp= '';
var manager = current.variables.manager.toString();
//gs.print(dept!=managerdepartment);
 
while(evp!=managerevp){
//gs.print("Testing");
 
var gr= new GlideRecord('sys_user');
gr.addQuery('sys_id',manager);
gr.query();
if(gr.next()){
if(gr.getDisplayValue('u_isevp').toString()!= evp){
//gs.print("hi");
 
manager=gr.getValue('manager').toString();
managerevp =gr.getDisplayValue('u_isevp').toString();
//answer.push(gr.sys_id);
}
else{
break;
}
}
}
//gs.info('hello ' +manager);
answer.push(manager);
1 ACCEPTED SOLUTION

gayatri38
Giga Guru

The code is good , Should fill all the evp fields as either yes or no, should not leave empty. Then it worked fine.

View solution in original post

3 REPLIES 3

Alp Utku
Mega Sage

Can you write the below script on If activity? If yes, you can proceed with approval

 

 

 answer = ifScript();

function ifScript() {
 if (request.requested_for.manager.evp=='true') {
       return 'yes';
   }
    return 'no';
 }

 

 

SanjivMeher
Mega Patron
Mega Patron

As suggested by @Alp Utku, you can have an If activity before proceeding. The other alternate is modifying your script as below

 

var answer = [];
var manager = current.variables.manager.toString();
if (current.variables.manager.u_isevp=='yes')
          answer.push(manager);

 


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

gayatri38
Giga Guru

The code is good , Should fill all the evp fields as either yes or no, should not leave empty. Then it worked fine.