Is there a way to execute a QueryTask synchronously?

5233
3
Jump to solution
02-11-2015 12:57 AM
BrianCachia
New Contributor II

I want to query a REST Service for the underlying Points/Polylines/Polygons.

ie. ../FeatureServer/0/query, ../FeatureServer/1/query and ../FeatureServer/2/query

Instead of nesting all the callbacks into each other I am trying to find a way to execute each query synchronously so that I can group the results in one array.

I also noticed there is a ../FeatureServer/query service that enables to query all the 3 underlying layers together but can this be achieved through the Javascript API Objects? A jquery synchronous ajax call would suffice but I would like to achieve this the proper way through the API.

Thanks

Brian

0 Kudos
1 Solution

Accepted Solutions
OwenEarley
Occasional Contributor III

If you are just using the REST API directly then a FeatureServer/query is the way to go to query multiple layers in a single request - note that this is still an asynchronous request.

If you are using the JavaScript API then you can group multiple QueryTasks into a DefferedList and process the results when all queries are completed. From your code it appears as though you are responding to a single request even though multiple server requests are sent.

You should look into Dojo DefferedLists as a way to combine the results of multiple query tasks. More information on them is available on this page - http://davidwalsh.name/deferredlist

View solution in original post

3 Replies
OwenEarley
Occasional Contributor III

If you are just using the REST API directly then a FeatureServer/query is the way to go to query multiple layers in a single request - note that this is still an asynchronous request.

If you are using the JavaScript API then you can group multiple QueryTasks into a DefferedList and process the results when all queries are completed. From your code it appears as though you are responding to a single request even though multiple server requests are sent.

You should look into Dojo DefferedLists as a way to combine the results of multiple query tasks. More information on them is available on this page - http://davidwalsh.name/deferredlist

BrianCachia
New Contributor II

Thanks for the help, i ll definitely look into the DefferedList.

0 Kudos
OwenEarley
Occasional Contributor III

Also, check out this post that uses the newer version of dojo promise lists:

Need help converting a DeferredList to use dojo/promise/all

0 Kudos