Populate Reference field based on another reference field (client script)

alexcharleswort
Tera Expert

Hi guys,

I am trying to populate one reference field based on another reference field and am having some difficulties. I need this to be an onChange client script, not a business rule (which would be much easier to accomplish but wont fulfill the functionality that I need).

In my catalog request I have a reference to the sys_user table (tvl_name). And then I have a reference field to my u_profile table (tvl_profile). On the u_profile table there is also a reference to the sys_user table (u_name).

Catalog Item

tvl_name (ref --> sys_user)

tvl_profile (ref --> u_profile)

u_profile

u_name (ref --> sys_user)

 

What I need to have happen is if tvl_name is filled in with my name, go search u_profile table where u_name == tvl_name and then fill out tvl_profile with that record. 

 

Any help would be greatly appreciated!

Thanks, 

AC

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

You need to use GlideAjax in your on change client script to achieve this functionality.

Please check below for more details on GlideAjax.

https://snprotips.com/blog/2016/2/6/gliderecord-client-side-vs-server-side

 

Regards,

Sachin

View solution in original post

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

You need to use GlideAjax in your on change client script to achieve this functionality.

Please check below for more details on GlideAjax.

https://snprotips.com/blog/2016/2/6/gliderecord-client-side-vs-server-side

 

Regards,

Sachin

Blagh, thats what I figured. I am awful at GlideAjax. I'll give it a go 😞

 

Thanks!

That was actually an incredibly helpful article and explained it super well! Was able to get it done in about 5 minutes. I'll have to bookmark that one.

 

Thank you!

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Alex,

 

I was about to suggest reference qualifier (no script required) but that will require users to select the value from tvl_profile variable. However, if you would like to auto-populate the value then you have to do it via GlideAjax approach. Below are few links to get started.

https://community.servicenow.com/community?id=community_blog&sys_id=f8ccee25dbd0dbc01dcaf3231f961978

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference/r_GlideAjax.html

 

-Pradeep Sharma