GlideRecord/Script in User Criteria

patricklatella
Mega Sage

Hi friends,

I'm building a User Criteria and need to have the script check the value of field on the logged in user's record in sys_user.

Trying a couple ways to do this and not finding the correct script.   Anyone see why this isn't working?   the top part that is querying to get the gr.u_region is working fine.   It's the getDomain part that does not seem to be working.   The field on the sys_user table I'm looking to see if it "== 'CTS'" is [u_ad_domain].

Thanks!

answer();

function answer(){

var loc = gs.getUser().getRecord().getValue('location');

var gr = new GlideRecord('cmn_location');

gr.get(loc);

     

var getDomain = new GlideRecord('sys_user');

getDomain.addQuery('sys_id',gs.getUserID());

getDomain.query();

if(gr.u_region == 'EMEA' && getDomain.u_ad_domain == 'CTS'){

return true;

}

}

1 ACCEPTED SOLUTION

Actually this is perfect



answer();



function answer(){


var getDomain = new GlideRecord('sys_user');


getDomain.addQuery('sys_id',gs.getUserID());


getDomain.query();



if (getDomain.next())


{


if(getDomain.location.u_region == 'EMEA' && getDomain.u_ad_domain == 'CTS'){


        return true;


}


}


}



Thanks,
Sanjiv


View solution in original post

11 REPLIES 11

Chris Sanford1
Kilo Guru

We were creating a similar script (a little different) and were having some issues. We resolved them by replacing "gs.getUserID()" with "user_name". We did find this docs site:

https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-manage...

and that's where they recommended the user_name. They specifically advise against gs.getUser() which I assumed would also apply to gs.getUserID(). It sounds like you got this working anyways but just an FYI on what we found.

Good to know, thanks Chris!