- 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 10:27 PM
Hi santoshi, i am getting null value with getXMLWait() function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 10:31 PM
Hello Anshul,
Can you share the code ? Also to mention xmlwait is not a best practise to use unless otherwise required. it will degrade the performance because of the wait function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 10:36 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 10:50 PM
In your script include, below line is wrong, you can not passing any sysparm_topic parameter from client script.
var topic = this.getParameter('sysparm_topic');
also, please use getValue() function in you if and else condition to get the value of sub_topic like : hr_topic.getValue('sub_topic');
Check of this helps. Also you please paste your script instead screen shot that would be easy for us to make correction in that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 11:00 PM
oh that screen shot is for another function,
please check below code, this code is working fine when i am using getXML(), but the only thing is its taking 1-3 secs time to show topic list so i want to use getXMLWait so that till 1-3 secs that screen should stop and only after we get answer from server than only we should be able to select topic.
If there is any other way to hold screen for 2-3 secs please let me know
getTopicBasedOnCategory: function() {
var topic_list = '';
var cat = this.getParameter('sysparm_category');
var hr_cat = new GlideRecord('x_prgm_hr_employee_hr_employee_care_topic_subtopic');
hr_cat.addQuery('category',cat);
hr_cat.query();
while(hr_cat.next()){
if(topic_list == ''){
topic_list += hr_cat.topic;
}
else{
if(topic_list.indexOf(hr_cat.topic) == -1){
topic_list += ','+ hr_cat.topic;
}
}
}
var answer = topic_list;
return answer;
},