How can I get the display value from oldValue in a client script?

gjz1
Giga Expert

I have a requirement to store the old display value of a reference field in a string field.  I'm using an onChange client script, but I can't figure out how to get the display value from oldValue.  Does anyone know how I can accomplish this?  What I have written returns the sys_id, I need the display value.

TIA

find_real_file.png

12 REPLIES 12

I already use this field, but it's not easily searched. The users already rejected this solution, they want a different field that only contains the specific data they are looking for.

Can you make the new field also a reference field? That way you can use oldValue and you can use that new field in searches.

Other option is to use a before update business rule with previous..getDisplayValue() and set that as the value of your field

This isn't a bad option and one I considered.  I think I'll try this option instead of the client scripts.  At least I can put everything into one code snippet instead of multiple client scripts.

 

Stephen Sturde
Tera Guru

Hi gjz,

If you need to use the display value in your script, your best bet is to put it through GlideAjax to a Script Include that does a GlideRecord get on the sys_id from that table and returns the string display value. You can then use the new value in your callback function as needed.

https://docs.servicenow.com/bundle/paris-application-development/page/script/ajax/topic/p_AJAX.html

-Stephen