- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 03:08 AM
Hi
I have written a code for onchange client script,
I want to populate different options for topic when differrent options are selected from category.
Every thing is working fine, its showing all the values correct, but after few seconds
for eg i have selected benefits in category and fastly i am selecting topic than its not showing any option, but when i have selected category and after 2-3 secs if i am selecting topic than i can see all the option,
So i believe this is some performance issue that my code is taking more time to populate option in topic field, you can see in below screenshots, first no options are coming , in second all option are coming when i selected topic after 2-3 secs
Below is the code which i have written for this
I am getting a list from my table, using script include, than populating through add option function
now here '--None--' option is coming as soon as i am changing category value which is not in for loop, so i believe for loop is taking a bit of time to perform action
What should i do here, so that my code run fast.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 04:35 AM
Hi Anshul,
If you want to use the script include, use getXMLWait() instead of getXML().
getXML() is asynchronous so the function 'DoSomething()' runs after you get data from ServiceNow. Getting data takes 2-3 seconds.
http://wiki.servicenow.com/index.php?title=GlideAjax#Synchronous_Glide_Ajax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 03:16 AM
Hello Anshul,
Instead of that code,
Try the below code with your variables:
var gp = new GlideRecord('sys_choice');
gp.addQuery('dependent_value', newValue);
gp.addQuery('element', 'u_subcategory');
gp.query();
if(!gp.hasNext()){
g_form.clearOptions('u_subcategory');
}
if(gp.next()){
g_form.addOption('u_subcategory', gp.value, gp.label);
g_form.setValue('u_subcategory', gp.value);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 03:26 AM
hi surya, we need to user client script not catalog client script,for client script we are bound to use glide record directly we have to use script include.
Please make me correct if i am wrong, the above will work with catalog client script i guess
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 03:31 AM
The above will also work for client scripts. try the above code and check which is performing at optimum rates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 04:35 AM
Hi Anshul,
If you want to use the script include, use getXMLWait() instead of getXML().
getXML() is asynchronous so the function 'DoSomething()' runs after you get data from ServiceNow. Getting data takes 2-3 seconds.
http://wiki.servicenow.com/index.php?title=GlideAjax#Synchronous_Glide_Ajax