Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Pulling the display value of a reference field into a string field...

_-jasonr-_
Giga Contributor

Hello All,

I am currently working on a form where I need to get a sys_user reference and then display the values into string fields on said form.

The following code gets the reference data, but when I set the values into the form, the location and department reference fields place the sys_id into the field.

function onLoad() {

    //Type appropriate comment here, and begin script below

   

  var reqName = g_form.getReference('u_reference_1', setEnhUserFields);

}

function setEnhUserFields(reqName) {

  g_form.setValue('u_string_3', reqName.user_name);

  g_form.setValue('u_string_4', reqName.phone);

  g_form.setValue('u_string_5', reqName.email);

  g_form.setValue('u_string_6', reqName.department);

  g_form.setValue('u_string_7', reqName.location);

}

Is there any way to get the display value of the location and department reference field display values into the string fields on the enhancement? Do I need a script include?

Thanks.

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee

Hello Jason,



You are right. You need to create a script include(client callable set to true) and call it via GlideAjax at the client side. More info here.


http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0



At server side, you can use getDisplayValue() to get the display value of the reference field.


http://wiki.servicenow.com/index.php?title=GlideRecord#getDisplayValue


View solution in original post

5 REPLIES 5

kristenankeny
Tera Guru

You might be able to dot walk to them:



g_form.setValue('u_string_6',reqName.department.name);


g_form.setValue('u_string_7',reqName.location.name);