var queryTask = new esri.tasks.QueryTask(layerServiceUrl); var query = new esri.tasks.Query(); query.where = "1=1"; query.outFields = []; query.outFields.push(field); query.returnDistinctValues = true;
Solved! Go to Solution.
For a temporary hack until the Query property supports the feature, try tacking it into your QueryTask url definition. It may not work in all cases.
example: var qtask = new QueryTask(url + "?returnDistinctValues=true");
As a side note, this hack doesn't work if you're using QueryTask.executeForCount. There's probably other places it doesn't work. We anxiously await the next release.
All,
This has been brought back to the attention of the JavaScript API team for inclusion in the next release:
See this thread:
Yes, implementing this is under consideration. In the mean time, it is possible to do with the current release of the JavaScript API (but without a nice and clean name like returnDistinctValues). The solution is to add the "esri/tasks/StatisticDefinition" module to your project. Then do the following:
1) Set the statistics type to "count" (see doc, statisticdefinition-amd | API Reference | ArcGIS API for JavaScript)
2) Set groupByFeildsForStatistics to the field of interest (see doc, query-amd | API Reference | ArcGIS API for JavaScript )
The result will be a short list of distinct values with respective feature counts. Hope this helps.
-Doug
PS or go with what Kelly suggests in the post Robert refers too.