- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 07:33 AM
Hello all,
I have a bit of an issue I've been poking around with for more than I would care to admit. I've been working on auto populating various string fields, which thanks to the Snow community I'm enjoying some success.
The script I am using is as follows:
function onChange(control, oldValue, newValue, isLoading) {
var ref = g_form.getReference('u_reference_4', setUser);
}
function setUser(ref) {
if (ref)
g_form.setValue('u_string_5', ref.u_end_user_name);
g_form.setValue('u_string_3', ref.u_rptc_income_st);
g_form.setValue('u_string_1', ref.company); // does not display value, only sys_id
}
Basically, when 'u_reference_4' is set to its value, u_string_5 and u_string_3 auto populate. - this works great...
My issue is, I need to auto populate one more field, u_string_1 from a value in a reference field from my user form that references the core_company table. When I script it in to the above, I either get a "undefined" error or the actual sys_id. I need the end users company name to also auto populate based on the employee ID set in u_reference_4.
Any assistance would be greatly appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 08:52 AM
Hi Daniel,
You can refer the below demo where I have created an example.
https://demo006.service-now.com/login.do
Username : admin
Password : admin
Client script : (BP) Set Location to User

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 08:52 AM
Hi Daniel,
You can refer the below demo where I have created an example.
https://demo006.service-now.com/login.do
Username : admin
Password : admin
Client script : (BP) Set Location to User
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 09:02 AM
Okay wow, that does exactly what I want it to... will follow-up shortly...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 10:50 AM
NP Daniel.
Please let me know if you are blocked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 01:28 PM
Thanks again Pradeep!
From your example, I found my mistake...
When I changed "u_string_1" to a reference field, my code was "ref.company.name" which is wrong and I didn't catch it. When I was looking over your example I tried "g_form.setValue('u_string_1', ref.company);" and it worked perfectly...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 08:06 AM
Also you can go through the dot-walkin method to pull the field of reference table.
http://wiki.servicenow.com/index.php?title=Dot-Walking