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 10:01 AM
I don't see anything incorrect with your script. Could you try the below:
answer = ifScript();
function ifScript() {
var output = 'no'; // Default: go through the normal approval process
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', '5de5599e873706d047f2a9350cbb3507'); // The Group where we are looking for the User
gr.addQuery('user', current.variables.common_default.var_requested_for.toString()); // Variable Set where the requested for is Located
gr.query();
if (gr.next()) {
output = 'yes'; // push the group approval
}
return output;
}
And to confirm , you were always seeing the if condition take the 'No' path?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 10:17 AM
This did not work either. welcome to my nightmare

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 10:51 AM
Interesting!
Time to try out weird stuff now:
- Change the gliderecord Object from gr to something else like memberObj
- Try out a part of our script in the background script:
var ritm = new GlideRecord('sc_req_item');
ritm.query('sys_id' , '<<drop your most recent RITM sysid here>>');
ritm.query();
if(ritm.next())
{
gs.info('requestor - ' + ritm.variables.common_default.var_requested_for.toString());
var memberObj = new GlideRecord('sys_user_grmember');
memberObj.addQuery('group', '5de5599e873706d047f2a9350cbb3507'); // The Group where we are looking for the User
memberObj.addQuery('user', ritm.variables.common_default.var_requested_for.toString()); // Variable Set where the requested for is Located
memberObj.query();
gs.info('record count - ' + memberObj.getRowCount());
if (memberObj.next()) {
gs.info('yes'); // push the group approval
}
else{
gs.info('no');
}
}//closing main gr
- Look for the log statements... do they appear fine?
- Checkout and re-publish your workflow and then raise a new request.
I agree, this truly is a nightmare lol ...