Service Now Development for Workflow Scripting
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2023 09:40 AM
My use case is as follows:
1. User creates a service now request
2. The approval is requested to respective vice president of the user
I want to stop the loop before the approval goes to CEO or CTO. I have provided a script below. Please suggest changes to implement the same.
answer = "";
var manager="";
var vpFound=false;
try{
var usr= new GlideRecord('sys_user');
usr.addQuery('sys_id', gs.getUserID());
usr.query();
if(usr.next()){
manager=usr.manager;
//if user has a manager
if(manager){
var vicePresident=getVP(manager);
vpFound=true;
answer = vicePresident;
}
else {
current.comments="Requesting user does not have a manager assigned";
}
}
}
catch(ex){
current.comments="Could not find Vice President for approval. Vice President or above approval is mandatory for the new connected organization";
workflow.info(ex);
}
function getVP(mgr){
var usr=new GlideRecord('sys_user');
usr.addQuery('sys_id',mgr);
usr.query();
var vpFound=false;
if(usr.next()){
var isVPTitle=usr.title.toLowerCase().indexOf('vp');
var isVDotPTitle=usr.title.toLowerCase().indexOf('v.p');
var isVicePTitle=usr.title.toLowerCase().indexOf('vice p');
var isVP = usr.u_vp;
if(isVicePTitle > -1 || isVPTitle > -1 || isVDotPTitle > -1 || isVP > -1){
vpFound=true;
return usr.sys_id;
}
else{
if(!vpFound){
return getVP(usr.manager);
}
}
}
}
I have also attached my workflow.
0 REPLIES 0