returnDistinctValues not returning distinct

1780
6
Jump to solution
02-06-2014 11:07 AM
jamesmuir
New Contributor II
I am trying to perform a query to return distinct values from my map service running on 10.1. The returned result has 1000 records (the max set in the server) and when i inspect it I am seeing duplicate values. Here is my code.

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;


Can someone tell me what I am doing wrong?
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Honored Contributor
That is not a property of Query yet. Take a look at this thread.

View solution in original post

0 Kudos
6 Replies
KenBuja
MVP Honored Contributor
That is not a property of Query yet. Take a look at this thread.

View solution in original post

0 Kudos
jamesmuir
New Contributor II
Unfortunately, you are correct. Thank you.
0 Kudos
KenDoman
Occasional Contributor II

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");

KenDoman
Occasional Contributor II

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.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

All,

   This has been brought back to the attention of the JavaScript API team for inclusion in the next release:

See this thread:

returnDistinctValues

DougCarroll
Esri Contributor

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.