How to fetch multiple value using GlideAjax?

Kashim Khan
Tera Contributor

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?

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

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

Mohith Devatte
Tera Sage
Tera Sage

Hello @Kashim Khan ,

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

Thank you

Hello @Kashim Khan 

If it worked for you can you please mark my answer correct and close the thread. This will help other users with same query