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