There are a lot of threads that talk about returning the coded domain values descriptions while using a queryTask but from the few examples I have seen using the 4.x API, I can't get anything to work. My code is below if anyone could help me. I haven't really found any examples along the same lines as to what I am trying to do.
//build query task
var queryTask = new QueryTask({
url: "https://services.arcgis.com/uHAHKfH1Z5ye1Oe0/arcgis/rest/services/misin_treatments_aquatic/FeatureServer/0"
});
//build query filter
var query = new Query();
query.returnGeometry = true;
query.outSpatialReference = view.spatialReference; //added for testing
query.outFields = ["*"];
//pass the url parameters.
var urlObject = urlUtils.urlToObject(window.location.href);
if (urlObject.query)
{
if (urlObject.query.id)
{ OID = urlObject.query.id; }
//set query based on the parameters
var treatmentid = "OBJECTID = '" + OID + "'";
query.where = treatmentid;
}
// execute query, place graphic on map and zoom to graphic
queryTask.execute(query).then(function(result){
console.log(result.features);
view.graphics.removeAll();
view.popup.close();
var resultFeatures = result.features;
resultFeatures.map(function(gra){
gra.symbol = sym;
view.graphics.add(gra);
gra.popupTemplate = popupTemplate;
// Provide graphic to a new instance of a Feature widget
const feature = new Feature({
container: "attributes",
graphic: gra,
map: view.map,
spatialReference: view.spatialReference
});
var AOI = result.features;
view.goTo(AOI);
});
});
Solved! Go to Solution.
Claire,
Below is a complete working htm document that you can use to create a file *.htm. This will output a domain value to the console of the web browser when you load it to a browser and click the button. I hope this helps so you can see the code work for yourself.
Claire,
You will have to use the CodedValueDomain | ArcGIS API for JavaScript 4.16 in order to get at the values.
Claire,
After more thought here is an easy way of getting the dmain values... This does a little more than asked...
Hi Aaron Booterbaugh Thank you for this information - I believe I have seen a similar snippet before but I was unsure where this should be included so I was unable to get it to work correctly. I'm still a bit of a novice when it comes to JavaScript so it is taking me a bit longer to make sense of the code and wrap my head around it. I am assuming that nothing in this snippet needs to be modified and I keep it as is?
With the CodedValueDomain, is this a property of a Feature Layer or is this it's "own thing" like :
var feature = new FeatureLayer ();
Claire,
Below is a complete working htm document that you can use to create a file *.htm. This will output a domain value to the console of the web browser when you load it to a browser and click the button. I hope this helps so you can see the code work for yourself.
Aaron Booterbaugh - this is INCREDIBLY helpful - thank you for your time and your help with this. I truly appreciate it.
Aaron Booterbaugh - I switched it to the feature service that is being used for this project, modified the field name and it doesn't seem to work. It does look like maybe the JSON is a bit different because the service in the example uses subtypes. I wonder if this has something to do with the feature layer not being public?
Clarie,
Subtypes have to be handle a little differently. Here is a new file that does both. This is method is not documented in the ESRI API but this has worked for years. ESRI API has so much more than they document. This is a fully working app so you can see it on the console.
Hi Aaron Booterbaugh - Ok so the first snippet you shared should work with this other feature service layer (the aquatic treatments used in my first post). As soon as I change to URL and the field name that has a domain set on it. It just returns the number
You will need to use the new code I sent. It looks a like but I added more functionality.