can we use GlideAjax 2 times in the same client script?

Bhavana Reddy
Mega Guru

Hello Guys,

We have a onchange client script written to automatically set the values of the catalog item onchange of "Quote" field and now we introduced the MRV's and we also need to automatically populate the values in the MRV based on the "Quote" value and i am thinking to create a seperate function in the script include and can we use 2 times the GlideAjax and call our seperate function and fill the MRV's data?

 

Please suggest me!!

1 ACCEPTED SOLUTION

So, in the script include, change to as follows. ServiceNow defaults field names to all lowercase.

obj["vendor"] = equipment.u_vendor+'';
obj["eqptype"] = equipment.u_equipment_type_model_no+'';
obj["quantity"] = equipment.u_quantity+'';
obj["racunt"] = equipment.u_rack_units+'';

View solution in original post

18 REPLIES 18

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi Bhavana,

Technically yes. You can call 2 glideajax in one client script.

But try to write down everything in one so that it will not make any impact on performance.

 

Regards,

Gunjan


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

In the same script include, 2 functions one for filling MRV's data and another one which was already existing and because of 2 functions i had to make 2 times GlideAjax call

But try to write down everything in one so that it will not make any impact on performance. ----> I am not finding the alternative way to achieve this except 2 times GlideAjax call, Please guide me if i am wrong somewhere

If you have script and possible to share then please share it.

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Sample script below as the whole script is too long to paste here

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

try {
var ID = g_form.getValue('customer_order_no');
// alert(ID);
// var CustOrderID = getDisplayValue(ID);
var ga = new GlideAjax('ACUXValues');
ga.addParam('sysparm_name', 'getCustomerOrder');
ga.addParam('sysparm_custOrd', ID);
ga.getXML(populateDetails);

function populateDetails(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");

if (answer) {

var returndata = JSON.parse(answer);
if (g_form.getValue('type_of_change') == 'Technical Data Change') {
g_form.setValue("opportunity_id", returndata.opportunity_no);
function setQuote() {
g_form.setValue("svo", returndata.svo_no);
}
window.setTimeout(setQuote, 2500);

}
if (returndata.Service_id != '') {
g_form.setValue("service_id", returndata.Service_id);
}
if (returndata.CSE_notes != '') {
g_form.setValue("cse_notes", returndata.CSE_notes);
}

g_form.setValue("is_pm_required", returndata.is_pm_required);

g_form.setValue("modem_type", returndata.Modem_Type);

if (returndata.Customer_Location != '') {
g_form.setValue("customer_location", returndata.Customer_Location);
}
if (returndata.colo == 'Yes') {
g_form.setValue("collocation", 'yes');
}
if (returndata.colo == 'No') {
g_form.setValue("collocation", 'no');
}

}

}

@2nd time again calling the script include with different function

var ga1 = new GlideAjax('ACUXValues'); // same script include
ga1.addParam('sysparm_name', 'getMRVData');
ga1.addParam('sysparm_custOrd', ID);
ga1.getXML(populateDetailsMRV);
function populateDetailsMRV(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");

if (answer) {

// logic to be implemented for filling MRV's from Custom table
}
}
} catch (err) {
jslog('Bhavana A JavaScript runtime error occurred: ' + err.message);
}