getReference displays sys_id for reference field

Alan Norris
ServiceNow Employee
ServiceNow Employee

Hi,

I'm trying to populate a set of variables based on the imput of another variable and can't quite find the answer i'm looking for.

for these 2 lines, i get the sys_id but would like the display value. (both fields are reference fields on the user record)

g_form.setValue('location', user.location);

g_form.setValue('cost_code',user.cost_center);

here is my variable script.

----

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

     

      if(!isLoading){

              if (oldValue != newValue) {

                      var User = g_form.getReference('name', fillcustomer);

              }

      }

}

function fillcustomer(user) {

g_form.setValue('phone',user.phone);

g_form.setValue('location', user.location);

g_form.setValue('desk', user.u_desk);

g_form.setValue('email',user.email);

g_form.setValue('cost_code',user.cost_center);

}

-----

I have trid the following but no joy.

//g_form.setValue('cost_code',user.cost_center.name);

//g_form.setValue('cost_code',user.cost_center.getDisplayValue());

//g_form.setValue('cost_code',user.code);

any help would be greatly appreciated

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Alan,



You mean when the value is set for the fields it displays sys_id. Any reason you want to have display value to be returned.


If you only want the display value to be returned, then the best way to do so is client script + GlideAjax.


Hi Pradeep,



correct.   this is for a catalogue Item, so the end user will see the values and the sys id means nothing to them.



ok,   Client script and GlideAjax?



not sure i've done a glide ajax before, I will give it a try .



any advice?


Thanks for the update. But in this case when the value is set on the field it will be display value only. Are you not seeing the display value on the reference field created on your table.


ok, so..



display value on table is set. - ok


display value shows in reference field on user record - ok



sys_id is diplayed in variable.



find_real_file.png