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

larstange
Mega Sage

HI Shihab



Have you tried doing a jslog(sys_id) or alert(sys_id) just to check that your variable actually contains a value?


Hi Lars,


Thanks for your reply.



The variable sys_id, do contains value as it is putting the value to the reference field. It set sys_id of a user in the reference field and I can see that user and go to the record when I click/hover on it. It definitely contains value and also setting the value in the field. But can't set the display value, which should be the name of that user.



Any idea, why that's not happening?


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.


Hi Lars,



Thanks a lot mate. That worked perfectly.



Thanks again.