Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Retrieve User Location with Catalog Client Script

spinol611
Giga Contributor

Hello!

Currently I am trying to query a user locations based off of the "requested_for" variable. The location of the user resides on the field "u_exp". The "requested_for" variable points to the sys_user table and is grabbing the logged in user as a default value. My final goal: If a user is from a certain location ex: US, then make another variable read-only and mark the checkbox true.

However I have not had any luck, even though I thought I was setting up the query correctly. Any help is much appreciated as I am new to the scripting.

Thanks!

var usr = g_user.userID();

var uq = new GlideRecord('sys_user');

uq.addQuery('sys_id',usr);

uq.query();

if(uq.next()){

        alert(usr);

}

1 ACCEPTED SOLUTION

find_real_file.png


Appreciate your help explorenow on pointing me in the right direction.



Thanks!


View solution in original post

11 REPLIES 11

Edit: Did get something working when I removed ".name". Will work it and post any other questions/answers.



Thanks!


yes, as recommended dot walking to field name, if u_exp is a string field the you don't need to do dotwalking, removing name should work for you.


explorenow ok I have it working 99% of the way but I am having problems with setting it to Read-Only. Here is my script:


find_real_file.png



The read-only works for the user that is populated into the "requested_for" variable. However, if I switch to another user that does not meet the criteria, the item remains read only, but doesn't check the box. Is there a way to fix this?



Thanks!


is citizen is true/false field? can you please remove the quotes when setting the value and try like



if(caller.u_exp == 'US'){


g_form.setValue('citizen', true); // remove quotes from true keyword


{


else{


g_form.setValue('citizen', false); // remove quotes from false keyword


}


find_real_file.png


Appreciate your help explorenow on pointing me in the right direction.



Thanks!