- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 02:26 AM
Hi Team,
I have a workflow for a catalog item where in which it will go for requested for manager's approval first once he approves i need to check whether the manager has a specific role if not it will go for second level approval.
I am not sure what i need to put inside the if condition post initial approval the one which i am trying is below and it is not working.
function ifScript() {
if (current.variables.requested_for.manager.hasRole('WFH_Approvers')) {
return 'yes';
}
return 'no';
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2021 02:19 AM
this will work and no need of query
answer = ifScript();
function ifScript() {
var roleArray = new global.ArrayUtil().convertArray(gs.getUser().getUserByID(gs.getUserID()).getRoles());
if(roleArray.indexOf('WFH_Approvers') > -1){
return 'yes';
}
return 'no';
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 02:36 AM
Try using below with added logs.
var mgrrole=current.variables.requested_for.manager;
gs.log('Manager is ',mgrrole);
if (mgrrole.hasRole('WFH_Approvers')) {
return 'yes';
}
return 'no';
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 02:43 AM
You can try something similar as below
var mgrrole=current.variables.requested_for.manager;
var m = new GlideRecord('sys_user_has_role');
m.addQuery('user', mgrrole);
m.addQuery('role', sys_id of your role);
m.query();
if(m.next())
{
return 'yes';
}
else
return 'no';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2021 02:19 AM
this will work and no need of query
answer = ifScript();
function ifScript() {
var roleArray = new global.ArrayUtil().convertArray(gs.getUser().getUserByID(gs.getUserID()).getRoles());
if(roleArray.indexOf('WFH_Approvers') > -1){
return 'yes';
}
return 'no';
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2021 02:13 PM
What if user has no roles... will it still work?