- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 03:56 AM
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]);
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 05:38 AM
Modify it like this
function onChangeMyChoiceField() {
if(newValue == "" || isLoading){
return;
}else if(oldValue != newValue){
//Your changes here
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 04:13 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 04:51 AM
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 !?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 05:01 AM
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]);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 05:14 AM
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() {
}