Can I use get display value in client script?

kiki330611
Kilo Expert

Hi everyone,

I am writing a client script in record producer to auto-fill a few user info fields based on the requester name (Your_name) entered. (The requester field is NOT a reference field)

I managed to write something below to find the requester name in user table and get the value for email, company and location :

find_real_file.png

My problem is the company and location fields in user table are reference field so they returned sys id...

I tried using gr.getDisplayValue but it doesn't seem to work in client script...

Can anyone suggest a way to get the display value for those two fields so I can auto-populate them in actual names not in sys id?

(It's returning like below now...)

Record.jpg

Thank you!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

I   recommend doing this with an Ajax call. You need more than just the user's information in this case. Using a GlideRecord query or getReference() will work, but you'll have to make multiple calls. GlideAjax (and the corresponding server side script include) can be more surgical.



Hint: return a JSON object with sys_id and display value and use three arguments for your g_form.setValue() otherwise, you're wasting another return trip to get the display values.



GlideAjax - ServiceNow Wiki


View solution in original post

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

g_form.DisplayBox('YOUR REFERENCE FIELD').value;


-Anurag

Not sure if it changed in the last 3 years but I tried g_form.DisplayBox('YOUR REFERENCE FIELD').value; and it didnt work

 

It seems that its actually g_form.getDisplayBox('your reference field name').value;

Yes James. 

g_form.DisplayBox('YOUR REFERENCE FIELD').value; used to work in the earlier versions, iof you see my reply was form 3 years back.

 

Thanks for sharing the new method for this. 🙂

-Anurag

Chuck Tomasi
Tera Patron

I   recommend doing this with an Ajax call. You need more than just the user's information in this case. Using a GlideRecord query or getReference() will work, but you'll have to make multiple calls. GlideAjax (and the corresponding server side script include) can be more surgical.



Hint: return a JSON object with sys_id and display value and use three arguments for your g_form.setValue() otherwise, you're wasting another return trip to get the display values.



GlideAjax - ServiceNow Wiki