Unable to set value for reference field via a script

Mike278
Kilo Explorer

Hi, I have a table with a column which is of a Reference type to another table. I can easily set the value in the GUI for the column fields by typing in a value or using the magnifying glass to search for it. But I am unable to set the value for this reference field via a script with setValue() method. The field basically remains blank and nothing happens. Is there a trick to set the value for a reference field with a script?
Of course, if I create another column with a type "String", then I can easily set its value with a script with setValue() method without any issues. Is there a difference between setting value for String fields vs Reference fields?

Thank you.

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

can you paste the script which you have used ? 

 

to set the value in reference field 

g_form.setValue('<reference field>','sysid of the record');

View solution in original post

3 REPLIES 3

Harsh Vardhan
Giga Patron

can you paste the script which you have used ? 

 

to set the value in reference field 

g_form.setValue('<reference field>','sysid of the record');

vkachineni
Kilo Sage
Kilo Sage

Please post your script.

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Dhananjay Pawar
Kilo Sage

Hi,

check this blog (point no. 2), you will get idea how to set value to reference field.

 

https://community.servicenow.com/community?id=community_article&sys_id=c918c3b8db968c5013b5fb2439961...

 

Thanks,

Dhananjay.