On change client script is not working fine

anshul_jain25
Kilo Guru

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

find_real_file.pngfind_real_file.png

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.

find_real_file.png

1 ACCEPTED SOLUTION

satoshi_yamamur
Kilo Expert

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


View solution in original post

15 REPLIES 15

I am not aware of any other way, but don't you think using getXMLWait() may kill your web page if there is delay in data loading, that more the delay the more the user session will be locked until the response is received. I think 1 to 3 sec should still be ok with getXML() function. what's your thought?



I am not an expert, we can get others opinion as well.


Yeah i know, but this is the first time i am facing issue with getXMl(), so thinking of using getXMLWait().




This is exactly what I mentioned in previous comments when Anshul wants to go with getXmlWait(). The reason you are looking for better code but in that process,getxmlwait will degrade the performances.


i found some information , since i am working in scoped application that is the reason i am not able to get any output while using getXMLWait.


getXMLWait not works in scoped application it only works in global appication, now i need to find that how can i pause my form for 3 secs when any value is selected from category.



can i use setTimeout(function()) here.



Now what i want is when i select any category than my form should get hang for 3 secs, and after that only i should able to choose topic.


Yes you can use setTimeout(function()) in client side. On server side you can use gs.sleep() if required.



can I use the SetTimeout() function within a business rule, or something equivalent?