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

ark6
Mega Guru

Hi Stephen,



Please check the below link. I have pasted a script here which will help you



Hide Variable based on Requester's Location



Regards,


Ark


spinol611
Giga Contributor

This is what I have so far and it is not working ark:



Onload Script:


find_real_file.png


Script include:


find_real_file.png


you can try with getReference() function to check the location field and the take appropriate action.



function onChange(control, oldValue, newValue, isLoading) {


    var caller = g_form.getReference('requested_for', doAlert);


}


function doAlert(caller) {


  if (caller.u_exp.name== 'US') //dot walk to location field name


    g_form.setDisplay('citizen', false); // Please check if citizen field name is correct


else


    g_form.setDisplay('citizen', true);


}


explorenow that was also unsuccessful. I have verified that "citizen" is the correct variable name on the catalog form. "u_exp" contains the information for the location as a single-line text string value