- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 09:29 PM
Hi All,
I have gone through the wiki (GlideAjax - ServiceNow Wiki ) about the synchronous and asynchronous use in glide ajax, but bit confused, could someone please let me know with an live scenario when to use getXML() & getXMLWait().
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2016 01:00 PM
Hi Mallikarjuna,
Asynchronous Example,
1) Say onChange of some field, you want to fill more fields on the form but the values are to be queried from database and then populate them on the form.
In this scenario, user can keep filling other fields on the form parallely. Why freeze the entire form and prevent user from using the form. So use asynchronous ajax call.
Synchronous Example,
2) Say onChange of some field, you are going to reload the entire form or hide/display many fields on form based on the validations done from server side.
In this scenario, some serious changes are going to be made to the UI and letting the user use it parallely would not be of any use here as the entire form might be reloaded based on the results. So use synchronous GlideAjax.
If I find a better example, will update here.
On Good practice perspective, try to stick with Asynchronous GlideAjax as much as possible as it increases usability of the form.
It will not wait for the response and let the user freely roam around on the UI and the response comes asynchronously.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 10:17 PM
getXML() - is used when you don't want user to wait for the response from the server. Best example is google suggestions. While we are typing in the search field it keeps on showing us the suggestion based on what we type. This is done using getXML() also called as asynchronous call.
getXMLWait() - is used when you want user to wait for the response from the server. Best example is when we are creating an email id. When we enter an email id it checks whether the typed email id is available or not and till then it doesn't allow us to perform any action on the page. This is done using getXMLWait() also called as synchronous call.
I hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 11:46 PM
Hi Mallikarjuna,
Async AJAX calls (getXML()) are always preferable for UI performance considerations.
So the question is really: what are the scenarios when you would want to use a synchronous (getXMLWait()) instead?
1) In general, anytime your remaining code depends on a value from the AJAX call in order to proceed, you would use getXMLWait().
2) If you didn't want the user to be able to select/change values on the form until after your AJAX request is processed, you would use getXMLWait().
3) If the remaining steps in your code could produce unpredictable results (e.g., records being inserted might need to be created in order, for attatchements to be added, etc), using getXMLWait() might be a good idea.
I would say that probably covers a majority of situations.
Thanks,
-Brian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2016 01:00 PM
Hi Mallikarjuna,
Asynchronous Example,
1) Say onChange of some field, you want to fill more fields on the form but the values are to be queried from database and then populate them on the form.
In this scenario, user can keep filling other fields on the form parallely. Why freeze the entire form and prevent user from using the form. So use asynchronous ajax call.
Synchronous Example,
2) Say onChange of some field, you are going to reload the entire form or hide/display many fields on form based on the validations done from server side.
In this scenario, some serious changes are going to be made to the UI and letting the user use it parallely would not be of any use here as the entire form might be reloaded based on the results. So use synchronous GlideAjax.
If I find a better example, will update here.
On Good practice perspective, try to stick with Asynchronous GlideAjax as much as possible as it increases usability of the form.
It will not wait for the response and let the user freely roam around on the UI and the response comes asynchronously.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2016 06:45 AM
Hi Maheshwar, I understood the scenario, thanks for providing info