returnDistinctValues not working in my query

Discussion created by schlot on Aug 26, 2015
Latest reply on Aug 27, 2015 by schlot

I have a queryTask based on the URL of my featureLayer.  This layer has 508 features in this layer.  My maximum record count on my service is much higher than that, to accommodate another layer with more features in it.  I'm using AGS 10.2.2 and Advanced Query Support says 'true'.


I'm using this queryTask as the source for a dropdown list, so I need to get just the distinct values from my AgencyAcronym field.  My queryTask executes, but instead of the 18 distinct values for this field, I'm still getting 508 features returned.  I'm having to run these through another function to remove the duplicates and I don't think I should have to do this.  I've tried a where clause of '1=1', because I want to check all records, but that doesn't make a difference, I still get all 508 features.


I have my queryTask set up as:

 //populates the pick list searching state facilities by agency       
     populateBuildingList: function(){
       app.buildingAgencyList.length = 0;
       var queryTask2 = new QueryTask(app.buildingLayer.url);
       var query = new Query();
       query.where = "AgencyAcronym is not null";
       query.outFields = ["AgencyAcronym"];
       query.orderByFields = ["AgencyAcronym"];
       query.returnGeometry = false;
       query.returnDistinctValues = true;
         on(queryTask2, 'error', function(err){
           console.log('error populating building list: ' + err.error)
       queryTask2.execute(query, lang.hitch(this, updateBGridHandler));
      function updateBGridHandler(results){
       console.log('results of updateBGridHandler :' + results.features.length + " records" );  //all 508 records returned. 
        arrayUtils.forEach(results.features, function(feature){
          var agencyName = feature.attributes.AgencyAcronym;
           agencyName = agencyName.replace(/^\s+|\s+$/g,'');
        var sortedList = common.sortAndRemoveDuplicates(app.buildingAgencyList);  //a function I'm having to use because the values aren't unique
        var data =, function(itm, idx){
          return {
            "id": idx,
            "name": itm,
            "value": itm
        var currentMemory = new Memory({
          data: data,
          idProperty: 'id'
        app.agencyDropdown.set("store", currentMemory);  //a grid created earlier