Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

When setting up a queryTask, what's the difference between queryTask.execute() and queryTask.executeForIds()?

In ESRI's JS API Reference, they have the exact same descriptions:

execute(parameters,callback?,errback?)

Executes a Query against an ArcGIS Server map layer. The result is returned as a FeatureSet. If the query is successful, the user-specified callback function is invoked with the result. A FeatureSet contains an array of Graphic features, which can be added to the map using Map.graphics.add(). This array will not be populated if no results are found.

executeForIds(parameters,callback?,errback?)

Executes a Query against an ArcGIS Server map layer. The result is returned as a FeatureSet. If the query is successful, the user-specified callback function is invoked with the result. A FeatureSet contains an array of Graphic features, which can be added to the map using Map.graphics.add(). This array will not be populated if no results are found.

The examples are slightly different, but I can't tell how these methods differ.

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

both methods call the same operation in ArcGIS Server, but as the name of the second implies (and your testing corraborates), the second returns the ObjectIds of matching features only.

Here is an example REST request (notice that returnIdsOnly is set to 'true')

http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3/query?where=STATE_NAME%3D%27California%27&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&returnGeometry=true&returnIdsOnly=true&returnCountOnly=false&returnDistinctValues=false&f=html

i'll make sure we correct the mistake in the API Reference. thanks for pointing it out!

share|improve this answer
add comment

I ran two identical queries, but used executeForIds on one and execute on the other. I inspected the returning results in Chrome Dev:

Object inspection

Unless I did something wrong, (which is always possible) it looks like the JS API Reference might be incorrect. executeForIds only returned an array containing the ObjectIDs of the matching items, while execute contained a FeatureSet.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.