Check to see if a user is a memeber of a group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 06:31 AM - edited 08-22-2024 06:31 AM
Team,
good day -
I have a request to add a process in workflow to push an approval if the "requested for" is a member of a group. other wise the process will move normallay. I have in the workflow a if statement but the script is not working and i was wondering what im doing wrong. can you advise
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 06:36 AM - edited 08-22-2024 06:38 AM
Try the below code and check
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user', "Your Variable");
grMem.addQuery('group.name', 'Group Name');
grMem.query();
if(grMem.next()){
answer = 'yes';
}
else{
answer = 'no';
}
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 09:37 AM
Tried this and it didnt work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 06:37 AM
Hello,
Do Check the below revised code:-
answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sys_user_grmember');
// Check if 'var_requested_for' is not null or undefined
var requestedFor = current.variables.common_default.var_requested_for;
if (!requestedFor) {
gs.info("Requested For is not defined.");
return 'no'; // Skip approval and move through the normal process
}
gr.addQuery('group', '5de5599e873706d047f2a9350cbb3507'); // The Group where we are looking for the User
gr.addQuery('user', requestedFor); // Variable Set where the requested for is Located
gr.query();
if (gr.next()) {
gs.info("User is a member of the group.");
return 'yes'; // Push the group approval
} else {
gs.info("User is not a member of the group.");
return 'no'; // Go through the normal approval process
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 09:37 AM
tried this and it did not work