0

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.

2 Answers 2

2

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!

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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