GlideAjax.getXMLWait spam for g_form.addOption() ???

Marcor1
Giga Contributor

Hello,

i know the following article about round trips of the serviceNow system

https://community.servicenow.com/community?id=community_blog&sys_id=b23deae5dbd0dbc01dcaf3231f961992&view_source=searchResult

but still i cannot figure out why the system is spamming

 "*** WARNING *** GlideAjax.getXMLWait - synchronous function - processor: AjaxClientHelper"

when i add options to a choice field on the incident form dynamically. The system is sending the following header each time an option is added (g_form.addOption()) to my custom choice list:

sysparm_processor: AjaxClientHelper
sysparm_scope: global
sysparm_want_session_messages: true
sysparm_name: getDisplay
sysparm_table: sys_user_group
sysparm_value: 
sysparm_synch: true
ni.nolog.x_referer: ignore
x_referer: incident.do

The options are retrieved by an asynchronous ajax call which works fine. As soon as the client script starts to loop over the retrieved options and add them to the choice field, the system starts spaming the synchrounous ajax calls ...

Does anyone know why the system behaves this way? The addOption function does not have a DisplayValue does it?

if (options.length > 0) {		
    g_form.addOption('myChoiceField', '', '-- None --');
    for (var i = 0; i < options.length; i++) {
        if(options[i] != null){					
            g_form.addOption('myChoiceField', options[i], options[i]);
        }
    }
 }
1 ACCEPTED SOLUTION

Modify it like this

function onChangeMyChoiceField() {

if(newValue == "" || isLoading){

return;

}else if(oldValue != newValue){

//Your changes here

}

}

View solution in original post

6 REPLIES 6

Alikutty A
Tera Sage

Hi,

I have seen this warning at several places. Can you try adding the script below and see if it make any change. The third parameter act as its display label but I don't see a reason why it should make synchronous call again.

g_form.addOption('myChoiceField', options[i].toString(), options[i].toString(), i);

Marcor1
Giga Contributor

I found out that each time an option is added, the onChange Script of the choice field is triggered, is there a way to filter addOptions out of the onChange trigger? I thought the onChange is only triggered as soon as the value of the specific field is changed !?

You can move it out of the scope from onChange function.

function onChange(){
 

 addChoices();
}

function addChoices(){
if (options.length > 0) { 
g_form.addOption('myChoiceField', '', '-- None --'); 
for (var i = 0; i < options.length; i++) { 
 if(options[i] != null){ 
   g_form.addOption('myChoiceField', options[i], options[i]); 
 } 
} 
}

 

The addOption loop is not located in the onChange script of the choice field.

funcction onChangeA() {

if (options.length > 0) { 
g_form.addOption('myChoiceField', '', '-- None --'); 
for (var i = 0; i < options.length; i++) { 
 if(options[i] != null){ 
   g_form.addOption('myChoiceField', options[i], options[i]); 
 } 
} 

}

Now onChangeA triggers onChangeMyChoiceField i times. I want onChangeMyChoiceField only be triggered if the value of myChoiceField has changed.

function onChangeMyChoiceField() {

}