- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 11:54 PM
Hello Guys,
We are facing the performance issue, The client script runs very slowly and it takes lot of time to load the value on the form.
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);
function setQuote() {
g_form.setValue("svo", returndata.svo_no); // wait untill other script loads the choices dynamically and then set the value
}
if (g_form.getValue('type_of_change') == 'Technical Data Change') {
g_form.setValue("opportunity_id", returndata.opportunity_no);
window.setTimeout(setQuote, 2000); // we are dynamically populating the options based on the Opportunity ID and hence we need to wait untill the other script loads the choices dynamically
}
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');
}
similarly we are setting more than 25 fields, sometimes the screen hangs and we manually need to refresh the form and window.setTimeout(setQuote, 2000); doesnot always work as expected
Please suggest if there any better approach
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2022 02:16 AM
Something like below. I've just created a stub Script Include.
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
try {
var ID = g_form.getValue('customer_order_no');
var ga = new GlideAjax('ACUXValues');
ga.addParam('sysparm_name', 'getCustomerOrder');
ga.addParam('sysparm_custOrd', ID);
ga.getXMLAnswer(function(answer) {
alert(answer);
var returndata = JSON.parse(answer);
var acuxResult = returndata.acuxResult; // get data for acux
var quotesResult = returndata.quotesResult; /// get data for quotes
if (g_form.getValue('type_of_change') == 'Technical Data Change') {
g_form.setValue("opportunity_id", returndata.opportunity_no);
var oppr = g_form.getValue('opportunity_id');
var answerArray = quotesResult.split(',');
g_form.clearOptions('svo');
g_form.addOption('svo', '', '--None--');
for (var i = 0; i < answerArray.length; i++) {
g_form.addOption('svo', answerArray[i], answerArray[i]); // dynamically adding the choices based on the opportunity field
}
}
g_form.setValue("svo", returndata.svo_no); // since this line executes early the value is not set,
if (acuxResult.Service_id != '') {
g_form.setValue("service_id", acuxResult.Service_id);
}
if (acuxResult.CSE_notes != '') {
g_form.setValue("cse_notes", acuxResult.CSE_notes);
}
g_form.setValue("is_pm_required", acuxResult.is_pm_required);
g_form.setValue("modem_type", acuxResult.Modem_Type);
if (acuxResult.Customer_Location != '') {
g_form.setValue("customer_location", acuxResult.Customer_Location);
}
if (acuxResult.colo == 'Yes') {
g_form.setValue("collocation", 'yes');
}
if (acuxResult.colo == 'No') {
g_form.setValue("collocation", 'no');
}
});
} catch (e) {
alert(e.message);
}
}
Script Include: ACUXValues. this is just a stub to return values. This is client callable
var ACUXValues = Class.create();
ACUXValues.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCustomerOrder: function() {
var result = {};
var acuxResult = {};
acuxResult['Service_id'] = 'service id';
acuxResult['CSE_notes'] = 'cse notes';
acuxResult['is_pm_required'] = true;
acuxResult['Modem_Type'] = 'modem type';
acuxResult['Customer_Location'] = 'Customer location';
acuxResult['colo'] = 'Yes';
var opno = 'opno';
acuxResult['opportunity_no'] = opno;
result['acuxResult'] = acuxResult; / set acux result
result['quotesResult'] = new QuoteDisplay().getQuotedetails(opno); // get and set quotes data. passing parameter 'opno'
return JSON.stringify(result); // convert to json and return it
},
type: 'ACUXValues'
});
Script Include: QuoteDisplay. This is not client callable
var QuoteDisplay = Class.create();
QuoteDisplay.prototype = {
initialize: function() {
},
getQuotedetails: function(oppr) {
var quotesResult = 'option1,option2,option2';
return quotesResult;
},
type: 'QuoteDisplay'
};
Execution result:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 12:02 AM
Hello there, Bhavana.
The issue could be related to the window.setTimeout(2000, setQuote);
If you only want to run this script after a few others, you can set the order(from the setting gear, take the order field & keep the number) for the client script, and it will run in that order.
If the above answer helps you, Please Mark Helpful & correct.
Cheers..!
Happy Learning 🙂
Tushar
Cheers..!

Happy Learning:)

Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 12:18 AM
Hi,
which other script you are referring?
why not merge the logic in single script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 02:01 AM
Hello Ankur,
we have 2 types of request
1)New - New request
2)Inflight Change - Change to the previous request submitted( all the details entered by the user in the previous request will be populated on the form )
2 fields we have Opportunity and quote ( depending on Opportunity, quote value is populated dynamically as a choice)
so for the inflight change we have to Populate the previous submitted value on the form, so i am using the window.setTimeOut function before setting the quote field ( because we need to wait untill the choices loaded dynamically from the other script then set the previously submited value during Inflight change)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2022 12:28 AM
Hi ANkur,
I tried merging the logic to first set the choices for the svo field and then set the choice from the previous customer order but still it doesnot set the value. I am using 2 glideajax calls in the single onchange client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
try {
//if(g_form.getValue('u_change_type')=='Update'){
// var ID = g_form.getDisplayBox('customer_order_no');
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);
function setQuote() {
g_form.setValue("svo", returndata.svo_no);
}
if (g_form.getValue('type_of_change') == 'Technical Data Change') {
g_form.setValue("opportunity_id", returndata.opportunity_no);
var oppr = g_form.getValue('opportunity_id');
var ga = new GlideAjax('QuoteDisplay');
ga.addParam('sysparm_name', 'getQuotedetails');
ga.addParam('sysparm_oppr', oppr);
// ga.addParam('sysparm_oppID', g_form.getValue('opportunity_id'));
ga.getXMLWait(populateDetails);
function populateDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var answerArray = answer.split(',');
// alert('QuoteValue:'+answerArray); // The correct value is returned
g_form.clearOptions('svo');
g_form.addOption('svo', '', '--None--');
//g_form.setMandatory('svo');
for (var i = 0; i < answerArray.length; i++) {
//g_form.addInfoMessage(answerArray[i]);
// g_form.clearOptions('quote_test');
g_form.addOption('svo', answerArray[i], answerArray[i]); // dynamically adding the choices based on the opportunity field
}
}
g_form.setValue("svo", returndata.svo_no); // since this line executes early the value is not set,
}
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');
}
Please suggest me, instead of setTimeout function, I am merging the script but still it doesnot work