How to fetch multiple value using GlideAjax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2022 08:24 AM
Suppose in my catalog item there are 4 fields like Requested_for, Manager, Location, Department.
So, i want autoPopulate all the fields based on Requested_For field using only GlideAjax so,how to do that?
can anyone provide scripts how to populate multiple values using GlideAjax?
- Labels:
-
Multiple Versions
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2022 08:32 AM
Hi
please use the example given at https://docs.servicenow.com/bundle/sandiego-application-development/page/script/ajax/topic/p_AJAX.ht...
And for testing purposes, you can use my GlideAjax Test Client
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2022 08:45 AM
Hello
Please refer below example :Please ensure your script include name is getStandardFields
Script Include: (Ensure the client callable checkbox is checked)
var getStandardFields = Class.create();
getStandardFields.prototype = {
getFields : function() {
var standardFields = new GlideRecord('sys_user');
standardFields.addQuery('sys_id', this.getParameter('sysparm_user'));
standardFields.query();
if(standardFields.next()) {
return standardFields.managerfield_backend_name + '|' + standardFields.location_backend_name+'|'+standardFields.department_backend_name;
}
return '';
},
type: 'getStandardFields'
};
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getStandardFields');//this is the script include
ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
ga.addParam("sysparm_user", newValue);
ga.getXML(getResponse);
}
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split('|');
g_form.setValue('manager_field_backend_name', values[0]);
g_form.setValue('location_field_back_End_name', values[1]);
g_form.setValue('department_field_back_end_name', values[2]);
}
}
Please mark this helpful if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 01:07 AM
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 02:02 AM
Hello
If it worked for you can you please mark my answer correct and close the thread. This will help other users with same query