I have written my code for unique values and get the count for each layer.The problem which i am getting is that my field "SubtypeCD" is domain coded value.
Following code is for unique value :
var unique = new QueryTask("http://localhost:6080/arcgis/rest/services/mydata/MapServer/1");
var query = new Query();
query.returnGeometry = false;
query.returnDistinctValues = true;
query.outFields = [
"SubtypeCD"
];
execute();
function execute () {
query.where = '1=1';
unique.execute(query, showResults);
}
var resultItems = [];
function showResults (results) {
var resultCount = results.features.length;
for (var i = 0; i < resultCount; i++) {
var featureAttributes = results.features.attributes;
for (var attr in featureAttributes) {
resultItems.push( featureAttributes[attr] );
}
}
console.log(resultItems);
}
The output i am getting in resultItems are 1,2 as my field is domain coded. What i need is to read the value name description which is PMT and GMT.
I don't think this helps you resolve the issue but hopefully it is still useful.
There are some documented bugs related to domain coded values being displayed instead of descriptions.
BUG-000098838: When using a domain to label a feature class before ..
BUG-000090470: The coded value domain descriptions display the code..
BUG-000088166: The coded value domain descriptions display the code..
Does anyone know if there is a way to specify a coded value or description when making a call for attributes using either the 3.x or 4.x Javascript API? A 'call for attributes' could be labels on the map, a pop-up window or an attribute table.
i have tried this https://community.esri.com/docs/DOC-8721-coded-domains-in-infotemplate but still no success.
Following is my complete code. I am using Arcgis 10.2.In log sub-domain is showing undefined.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Query distinct values without map</title>
<script src="https://js.arcgis.com/3.22/"></script>
<script>
require([
"esri/layers/CodedValueDomain",
"esri/InfoTemplate","dojo/_base/array",
"esri/layers/FeatureLayer",
"esri/layers/Field",
"esri/tasks/QueryTask",
"esri/tasks/query",
"dojo/_base/lang",
"dojo/dom",
"dojo/on",
"dojo/domReady!"
], function(
CodedValueDomain,
InfoTemplate,array,
FeatureLayer,
Field,
QueryTask,
Query,
lang,
dom,
on
) {
var queryTask = new QueryTask("http://localhost:6080/arcgis/rest/services/mydata/MapServer/1");
var query = new Query();
query.returnGeometry = false;
query.returnDistinctValues = true;
query.outFields = [
"SubtypeCD"
];
on(dom.byId("execute"), "click", execute);
function execute () {
query.where = '1=1';
queryTask.execute(query, showResults);
}
function showResults (results) {
var resultItems = [];
var resultCount = results.features.length;
for (var i = 0; i < resultCount; i++) {
var featureAttributes = results.features.attributes;
for (var attr in featureAttributes) {
var test=getSubtypeDomain(queryTask,featureAttributes[attr] ,"SubtypeCD");
//var codedValue = _getCodedValue(queryTask,"SubtypeCD",featureAttributes[attr])
// resultItems.push("<b>" + attr + ":</b> " + featureAttributes[attr] + "<br>");
resultItems.push("<b>" + attr + ":</b> " + test+ "<br>");
}
resultItems.push("<br>");
}
dom.byId("info").innerHTML = resultItems.join("");
}
var subTypeVal;
function getSubtypeDomain (featureLayer,fieldVal, fieldName){
if (featureLayer.typeIdField!=null) {
console.log("Have Subtypes");
if (fieldName==featureLayer.typeIdField) {
array.forEach(featureLayer.types, lang.hitch(this, function (lsf) {
if (fieldVal==lsf.id){
fieldVal=lsf.name;
subTypeVal=lsf.id;
}
}));
} else {
array.forEach(featureLayer.types, lang.hitch(this, function (lsf) {
if (lsf.id==subTypeVal){
array.forEach(lsf.domains[fieldName].codedValues, lang.hitch(this, function (domain) {
if (fieldVal==domain.code){
fieldVal=domain.name;
}
}));
}
}));
}
} else {
console.log("No Subtypes");
subTypeVal=null;
array.forEach(featureLayer.fields, lang.hitch(this, function (ldf) {
if (ldf.name==fieldName){
if (ldf.domain){
array.forEach(ldf.domain.codedValues, lang.hitch(this, function(domain){
if (fieldVal==domain.code){
fieldVal=domain.name;
}
}));
}
}
}));
}
console.log( fieldVal);
return fieldVal;
};
});
</script>
</head>
<body>
<input id="execute" type="button" value="Get Details">
<br />
<br />
<div id="info" style="padding:5px; margin:5px; background-color:#eee;">
</div>
</body>
</html>
I don't quite understand what the goal is here. If you get a chance, please go into a little more detail about what you're trying to accomplish.
I've done a little work with domains and I believe domain information is included on each layer on a feature service. When you add that layer to the map or load it, the client gets all the domain information and you should be able to query by specific attributes that have a domain.
I am getting the attribute value ( 1, 2,3 ....) but not the actual value(PMT,GMT...)
After investigating i found the issue.It was my layer not ready. Placement of code was wrong.Thank you all.