- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2022 04:05 AM
Hi all,
i have a requirement,
i have 1 group. if the user related to that group i need to skip the approval other wise i need to send the approval for requested manager?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2022 07:20 AM
Hi,
you didn't tell user variable is of what type?
Is group name correct?
Also the script I shared would work provided the user variable is reference to user table
You said you want to skip the approval when user is part of group then you should return no when that user is member
answer = ifScript();
function ifScript(){
var isMember = gs.getUser().getUserByID(current.variables.user+'').isMemberOf('Software');
if(isMember)
return 'no'; // take this output to next activity
else
return 'yes'; // take this output to approval activity
}
OR
answer = preapprovalcheck();
function preapprovalcheck() {
var user = current.variables.name;
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user', user);
grMem.addQuery('group.name', 'Software');
grMem.query();
if (grMem.next()) {
return 'no';
} else {
return 'yes';
}
}
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
‎06-03-2022 06:31 AM
Try below
answer = preapprovalcheck();
function preapprovalcheck() {
var user = current.variables.name;
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user', user); //changed sys_id to user
grMem.addQuery('group.name', 'Software');
grMem.query();
if (grMem.next()) {
return 'yes';
} else {
return 'no';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2022 07:14 AM
using this script i am still getting approvals.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2022 07:20 AM
Hi,
you didn't tell user variable is of what type?
Is group name correct?
Also the script I shared would work provided the user variable is reference to user table
You said you want to skip the approval when user is part of group then you should return no when that user is member
answer = ifScript();
function ifScript(){
var isMember = gs.getUser().getUserByID(current.variables.user+'').isMemberOf('Software');
if(isMember)
return 'no'; // take this output to next activity
else
return 'yes'; // take this output to approval activity
}
OR
answer = preapprovalcheck();
function preapprovalcheck() {
var user = current.variables.name;
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user', user);
grMem.addQuery('group.name', 'Software');
grMem.query();
if (grMem.next()) {
return 'no';
} else {
return 'yes';
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader