How to get display value of any reference field using Client script?

rathikaramamurt
Giga Expert

Hey,

Could anyone please advise on how to get the display value for any reference field (CI field) using the onSubmit Catalog Client script?

Using g_form.getValue('u_device_ref_1'), I am getting the sys_id of this field

And with g_form.getDisplayValue('u_device_ref_1'), I am getting blank value.

Thanks in Advance,

Rathika.

1 ACCEPTED SOLUTION

PrashantLearnIT
Giga Sage

HI Rathika,



You can use g_form.getDisplayBox('field_name');



Thanks


Prashant


********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

View solution in original post

25 REPLIES 25

Nalin Bisht
Tera Contributor

You can use g_form.getDisplayValue() on the catalog client script, but make sure that the 'Isolate script' Field is set to false if it's not working on true.

In this Client script, the Current_position field is a reference type field and I am copying its value on the future_position field.

find_real_file.png

That is not best practice an may not always work. g_form.getDisplayBox or using a script include is the best way to go.

g_form.getDisplayBox is not working for me in the catalog client script. And, the example I gave above is for catalog client script only. I'm not sure if it will work on other client scripts as well.

P.s. - I Agree that Script Include will be the best practice for getting the display value of a reference field in the client script.

Did you do it as g_form.getDisplayBox('').value? A lot of people forget to add .value.

I tried this one too, it shows a javascript error. I think g_form.getDisplayBox() is not supported on new versions.

find_real_file.png