Populate a reference variable on a catalog item - catalog client script

Nate23
Mega Guru

Hello all,

 

I have tried a number of things, but can't seem to populate this reference field. Here is the scenario:

 

This Catalog Item has a reference variable to pull current user from the sys_user table. I have another reference field on the catalog item to the cmn_location. This is also a reference field in the sys_user table. The client wants their location to auto populate. I tried dot walking, and querying, but can't seem to get the reference field to populate. when I try to display this is an alert I get [Object] [Object].

 

I've went through my stages of different code, but for visual purposes here is the onLoad client script:

 

var gr = new GlideRecord('sys_user');  
      gr.addQuery('user_name', g_form.getValue('customer_info_requestor'));  
      gr.query();  

      while(gr.next()){

              g_form.setValue('visitor_access_which_post', gr.location);  

      }

 

Any Ideas?

1 ACCEPTED SOLUTION

Nate23
Mega Guru

Found the solution, just took a lot of testing and . Thanks for y'alls help!



In case someone else runs into this problem here was the solution:



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


      if (newValue == '') {


              g_form.setValue('visitor_access_which_post', '');


              return;


      }


     


      if (!g_form.getControl('visitor_access_which_post'))


              return;


     


      var caller = g_form.getReference('customer_info_requestor', setLocation);


}



function setLocation(caller) {


      if (caller)


              g_form.setValue('visitor_access_which_post', caller.location);


}


View solution in original post

3 REPLIES 3

ohhgr
Kilo Sage

Hi Nathan,



Could you try using "variables" prior to variable name? Check if that does any difference in the outcome



Thanks,
Mandar


Hey Mandar,



This is a catalog client script, not a client script, so if you mean using variables.variable_Name this does not work either. It's driving me crazy.



Thanks,


Nathan


Nate23
Mega Guru

Found the solution, just took a lot of testing and . Thanks for y'alls help!



In case someone else runs into this problem here was the solution:



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


      if (newValue == '') {


              g_form.setValue('visitor_access_which_post', '');


              return;


      }


     


      if (!g_form.getControl('visitor_access_which_post'))


              return;


     


      var caller = g_form.getReference('customer_info_requestor', setLocation);


}



function setLocation(caller) {


      if (caller)


              g_form.setValue('visitor_access_which_post', caller.location);


}