We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Set Display Value of UI Reference field from UI Script

Shihab Ahmed
Tera Contributor

Hi All,

I am trying to populate value into a ui_reference field in my UI Page for service catalog.

Below is the code on UI page:

<g2:ui_reference name="u_exec_leadership_team" table="sys_user" value="$[test]" displayvalue="$[name]" onchange="setCartValue();" />

So, the page loads with value from "$[test]" and "$[name]" variable.

But I using onchange function in another field on the page to call a UI script function, which changes these value.

So the UI Script function does some evaluation and then set value of 'u_exec_leadership_team'. Below is the code, I used to set the value:

g_form.setValue('u_exec_leadership_team', sys_id);

This gives value to the UI Reference field but display shows as "undefined".

I have tried using "g_form.DisplayValue('u_exec_leadership_team', name);". But it still shows undefined and doesn't show the name.

"name" here is the corresponding name to the above used sys_id.

Am I using the correct syntax to set the Display value for UI page or there is some other method?

Please help.

Thanks

Shihab

1 ACCEPTED SOLUTION

larstange
Mega Sage

You can set the display value directly by doing



g_form.setValue('u_exec_leadership_team', sys_id,name);



Where "name" contains your display value.


View solution in original post

5 REPLIES 5

Kalaiarasan Pus
Giga Sage

I had done this in Fuji but not sure on newer versions.



gel('fieldname').value = 'sys id of record';


gel('sys_display.fieldname').value = 'display value of record';