- 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
‎05-30-2022 04:14 AM
Hi,
is this for catalog item?
Which user is related to that group?
The user who submitted the request? OR any user reference variable you have in your catalog form
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
‎05-30-2022 04:24 AM
Hi Ankur,
yes it's a catalog item, in form i have a field and it's reference field (sys_user). which user i selected in that field that user available in xyz group i need to skip approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2022 04:35 AM
Hi,
you can use IF activity in workflow and check that
answer = ifScript();
function ifScript(){
var isMember = gs.getUser().getUserByID(current.variables.variableName+'').isMemberOf('Group ABC');
if(isMember)
return 'no'; // take this output to next activity
else
return 'yes'; // take this output to approval activity
}
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:14 AM
Hi Ankur,
it's not work for me so i written below script(still approval trigger whether user related to group also)
answer = preapprovalcheck();
function preapprovalcheck() {
var user = current.variables.name;
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('sys_id', user);
grMem.addQuery('group.name', 'Software');
grMem.query();
if (grMem.next()) {
return 'yes';
} else {
return 'no';
}
}