checking if a reference field is in a group

Rick Forristall
Tera Guru

I have a reference field called hiring manager (u_hiring_manager) that reference the user table.

 

In a UI policy I need to find out if the hiring manager is in a group.

 

I've been at this for several hours - not finding any direct solutions.

 

I've tried:

var hm = g_form.getReference('u_hiring_manager', setAValue);

 

to get the hiring manager's user information. Then I tried:

hm.isMemberOf('group name') - didn't seem to work

hm.sys_id.isMemberOf('group name') - didn't seem to work.

 

Any help will be much appreciated.

 

Thanks,


Rick Forristall

Goodwill of Central Arizona

1 ACCEPTED SOLUTION

I would put an alert in as the first line in your 'onCondition' function to check that the UI policy condition is even firing and getting into the script.   I have mine set up as a client script.   You can log into demo003 here...



https://demo003.service-now.com/side_door.do


View solution in original post

18 REPLIES 18

That looks like it should work fine.


I just submitted a request as a non-member of IT ServiceDesk, and I made sure that my 'requested_for' value was different than my 'u_requested_by' value, and the email did not fire off.



Any idea why this would not work? Could it be that I'd have to make a second "if" portion of code uniquely for my "current.u_requested_by == current.requested_for" to result in answer = false?


It could be any number of things.   I would suggest adding some 'gs.log' entries in there to output data to the logs so that you can see what's happening.


Looks like I got it working in the end. My issue was that I thought the "answer = true" meant the entire advanced condition was equating to true, when instead it's the email being sent = true. Furthermore, because I am working with "not" situations, I really would want to use an AND operator, instead of an OR.



My final working code is as follows. Hopefully, it has the Crossfuze seal of approval:



var grp = new GlideRecord('sys_user_grmember');


grp.addQuery('group.name', 'IT ServiceDesk');


grp.addQuery('user', current.u_requested_by);


grp.query();



if (!grp.next() && current.u_requested_by != current.requested_for) {


  answer = true;


}