The CreatorCon Call for Content is officially open! Get started here.

Check to see if a user is a memeber of a group

Walter Toney
Tera Expert

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

 

answer = ifScript();

function ifScript() {
    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); // Variable Set where the requested for is Located
    gs.info(current.variables.common_default.var_requested_for.toString()); 
    gr.query();
    if (gr.next()) {
        gs.info("user is real");
        return 'yes';   // push the group approval
    } else {
        gs.info("User is not Real");
        return 'no'; // go through the normal approval process

    }
}
7 REPLIES 7

AnirudhKumar
Mega Sage

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?

This did not work either. welcome to my nightmare

 

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 ...