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.

Getting value of reference field from user table in Catalog Client Script

n_kishore
Giga Contributor

I am having a requirement where i have to get the field values and show it in Catalog item when the requestingfor field is changed.
I wrote a client script and querying the data from User table for the user in requestingfor field.
How ever there is a field in User table called Location which is a reference field. I need to read that in my following script.

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

      var userRec = g_form.getReference('requestingfor', getTermedRec);

  function getTermedRec(userRec){

  if(!isLoading && newValue != oldValue){

  g_form.setValue('req_', userRec.title);

  g_form.setValue('requester_email', userRec.mobile);

* i need to get the value of location which is a reference field in User table. Where as above two fields were single line text field.
I cannot do     g_form.setValue('requester_location', userRec.location); its not working.

}

  }

  }


Can anyone please help me get the script to read the display value, Let me know if you need additional info to assist.

Thanks,
Nanda

1 ACCEPTED SOLUTION

Your current script should work, if you change it to reference type.


View solution in original post

10 REPLIES 10

Try



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




if(newValue=='')


{


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


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


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


}




if(!isLoading && newValue != oldValue){


var userRec = g_form.getReference('requestingfor', getTermedRec);


}




}



function getTermedRec(userRec){


g_form.setValue('req_', userRec.title);


g_form.setValue('requester_email', userRec.mobile);


g_form.setValue('requester_location', userRec.location);


}