- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2022 09:38 AM
Hello, I am using below client script to auto populate field values ('manager' and 'lastname'), when user in 'requested_for' field changes
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var id = g_form.getValue('u_requested_for'); // ref to sys_user
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',id);
gr.query();
while(gr.next()) {
g_form.setValue('u_manager',gr.manager);
g_form.setValue('u_lastname',gr.last_name);
}
}
As its not best practice to use gliderecord in client script, can someone help to get the code for script include and client script, if I want this to get done using 'GlideAjax'.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2022 09:41 AM
Hi there,
This article which I wrote a while back gives some good explanation and examples:
- 2020-01-10 Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2022 09:41 AM
Hi there,
This article which I wrote a while back gives some good explanation and examples:
- 2020-01-10 Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2022 09:43 AM
Hey,
You can refer to below community article which meets your requirement.
Also, would suggest to have a look at Article shared by Mark above, will be helpful in order to understand how Ajax works.
Get Manager name based an selected user
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2022 09:50 AM
Do be aware, that the link you are sharing, the answer marked as correct a performance issue if using this for a reference field/variable.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field