UI Policy : Getting Display Value

jeremyeperdue
Giga Expert

How can I getDisplayValue on a field while I am working in a UI Policy?

When certain criteria is met with what the user selects, I want to populate the short description with the value of the choice list. I can get the sys_id of course, what is the easiest way for me to get the display value of said field?

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Jeremy,



You can get the display value of the reference field with the below piece of code.


var caller = g_form.getDisplayBox('caller_id').value; //Replace caller_id with the exact field column name as per your requirement.


View solution in original post

7 REPLIES 7

I would argue that it is a very bad idea to use getDisplayBox in production code.   This method is not in the api documentation, and is also not displayed in the SN script "intellisense" popup.   I would not be surprised if this method was deprecated already.



I would argue that the best practice would be to create a glideajax call using the sys_id   from g_form.getValue to fetch the field display value from a client callable script include that queries the same table the reference field variable is attached to.



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




Capture_undocumented_api_call.PNG


Within the same UI policy, how can I get the old value of a field?



Thanks!


Charlie


I realize this is an old thread, but thought it is important to point out that g_form.getDisplayBox does not appear to work in Service Portal.



Also, if you need to use GlideAjax in an onSubmit script to get a display value, you will need to do some additional work. After your async call, you will need to cancel the submit (return false) and then re-submit the form at the end of your callback. Otherwise the system will not return a value before the form submits. That assumes you need the value before the form submits. This does not apply to UI policy but is important to note for client scripts.