How to set value to reference field using sys_id

peshwen
Giga Contributor

Hi all,

I am having sys_id of company name and i want to set that company name to reference field using sys_id.So how to do it?Please anyone can tell?

25 REPLIES 25

Hi Berny,


Thank you so much for your help.I got the issue solved.




Thanks,


Nikhil


That's great Nikhil peshwen! Would you mind marking the answers as correct/helpful so that we can close this thread?



Thanks,


Berny


I am referring to user table for a field.The "first name" value should be displayed when I select the user from the list.But the display value is set to true for "name " field,which should not to be changed.So,Is it possible to display the first name without changing the display value.Any suggestions..


Hi Nikhil,



The one Berny has suggested above will solve your problem I guess.


Because you are declaring the variable answer inside the function and using that outside it , where the scope of variable is not there.



As a best Practice , it is better to set Value and display value while using setValue function.


g_form.setValue(fieldName, value, [displayValue])


rehani
Tera Contributor

Hi,



Best practice would be to provide both the sys_id and display value if you have them.   This saves one extra lookup.



Take a look at the wiki GlideForm (g form) - ServiceNow Wiki   under the section labelled 11.5 setValue