- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2022 01:04 PM
On the below request form from our service catalog, I would like the group of text boxes / reference fields to auto-fill based on the user data from the first reference field. I have been seeking an onChange Catalog Client Script / Script Include to get this done, but have had no success. Any help is appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 08:35 AM
I figured it out!
The key was this small bit of code, which passes the, "newValue" variable to the sysparm_state variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("ASHNUserDetailsUtil");
ga.addParam("sysparm_name", "user_info");
ga.addParam("sysparm_state", newValue);
ga.getXML(ajaxResponse);
Catalog Client Script
Script Inlucde: Client callable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2022 01:18 PM
This is a clear case of executing server side data from client side where you have to pull the user's info from the sys_user table as soon as the employee name is entered in the first reference field.
Instead of the on change client script, please use GlideAjax which passes parameters to the script includes, and, using naming conventions, allows the use of these parameters.
The below docs article from ServiceNow should be helpful.
https://docs.servicenow.com/en-US/bundle/tokyo-application-development/page/script/ajax/topic/p_AJAX.html
Please mark my answer correct/helpful if it helped you in any way. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2022 09:19 AM
Thank you. This got me closer, but I'm still not quite to my requirement yet. I now am able to populate data into the form automatically, but there's two problems, with screenshots below.
1) The user info being populated is the logged in user. The template I worked from was built to accomplish this, so I'm not shocked there, but I can't find a solution to instead have the reference be from my Reference Field, "employee_to_be_terminated"
2) I am getting data onLoad, but it should only be onChange
Script Include:
Catalog Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 08:35 AM
I figured it out!
The key was this small bit of code, which passes the, "newValue" variable to the sysparm_state variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("ASHNUserDetailsUtil");
ga.addParam("sysparm_name", "user_info");
ga.addParam("sysparm_state", newValue);
ga.getXML(ajaxResponse);
Catalog Client Script
Script Inlucde: Client callable