How to query and select three shapefile under one name as one unique value

723
5
08-04-2017 12:40 AM
FaryalSafdar
New Contributor

i am encountering problem with query i have to select three shapfile under one name as one unique value. it worked in arcmap but it does not work with arcgis javascrip api. my query is 

esriRequest({
              url: "http://localhost:6080/arcgis/rest/services/........./query?where=Name ='" + id.toString() + "'&outFields=Soil&returnGeometry=false&orderByFields=Soil&returnDistinctValues= true&f=json",
              content: {
                f: 'json'
              },
              handleAs: 'json',
              callbackParamName: 'callback',
              timeout: 15000
            }).then(lang.hitch(this, function(response) {
              var store2 = new Memory({
                data: []
              });but in coding when i have applied query it populate combobox like this in below image could anyone tell me what i am doing wrong? 
0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Faryal,

   So what is returned when you just paste a test url in your browser like:

http: //localhost:6080/arcgis/rest/services/........./query?where=Name ='.........'&outFields=Soil&returnGeometry=false&orderByFields=Soil&returnDistinctValues= true&f=json

Do you get three values back or just one. If you get there then the query or underlying data is your issue.

0 Kudos
FaryalSafdar
New Contributor
{"displayFieldName":"Id","fieldAliases":{"Soil":"Soil"},"fields":[{"name":"Soil","type":"esriFieldTypeString","alias":"Soil","length":50}],"features":[]}

it returns this.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Faryal,

   The query did not return any features. So did you put an appropriate value in the 

Name='.........' portion of the url?

0 Kudos
FaryalSafdar
New Contributor

it returns this when i put query in the query form of layer

{

"displayFieldName": "Id",

"fieldAliases": {

"Soil": "Soil"

},

"fields": [

{

"name": "Soil",

"type": "esriFieldTypeString",

"alias": "Soil

",

"length": 50

}

],

"features": [

{

"attributes": {

"Soil": "Soil Map"

}

},

{

"attributes": {

"Soil": "Soil Map"

}

},

{

"attributes": {

"Soil": "Soil Map"

}

}

]

}

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Faryal,

  That is very strange that your server is not returning distinct values for the SOIL field. When I do this type of query on my ArcGIS Server I only get distinct values:

http: //gis.calhouncounty.org/arcgis2/rest/services/ParcelViewer/MapServer/67/query?where=NAME+LIKE+... 

Results:

{
 "displayFieldName": "PARCEL_NUMBER",
 "fieldAliases": {
  "SUBDIVISION": "Subdivision"
 },
 "fields": [
  {
   "name": "SUBDIVISION",
   "type": "esriFieldTypeString",
   "alias": "Subdivision",
   "length": 12
  }
 ],
 "features": [
  {
   "attributes": {
    "SUBDIVISION": ""
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "BD1A"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "C0"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "GC3A"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "GRVSB"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "HT1"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "JOE"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "LE0"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "LEHA"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "LLS11"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "LP"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "LTC"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "P7"
   }
  },
  {
   "attributes": {
    "SUBDIVISION": "SHH0"
   }
  }
 ]
}

So you may need to contact esri tech support if you are currently under maintenance. If not then you can use some JS code to get the distinct values from the results on the client side:

function getDistinctValues(array) {
        var flags = [],
          output = [],
          l = array.length,
          i;
        for (i = 0; i < l; i++) {
          if (flags[array[i]]){
            continue;
          }
          flags[array[i]] = true;
          if (array[i] === ' ') {
            continue;
          }
          var uVal;
          if (array[i] === null) {
            uVal = {
              code: 'null',
              name: 'null'
            };
          } else {
            uVal = {
              code: array[i],
              name: array[i]
            };
          }
          output.push(uVal);
        }
        return sortByKey(output, "code");

        function sortByKey(array, key) {
          return array.sort(function (a, b) {
            var x = a[key];
            var y = b[key];
            if (typeof x == "string") {
              x = x.toLowerCase().trim();
              y = y.toLowerCase().trim();
            }
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
          });
        }
      }
0 Kudos