Is it possible to return coded domain values using QueryTask in the JavaScript API? FindTask seems to do it ok, no luck with QueryTask.
William,
Query Task does not do this for you. You as the developer have to get the coded values in code.
Here is a snippet function that I use in some widgets.
_getCodedValue: function (layer, fieldName, fieldValue, typeID) { var result; var codedValueDomain; if (typeID) { var featureType = this._getFeatureType(layer, typeID); if (featureType) { codedValueDomain = featureType.domains[fieldName]; } } else { var field = this._getField(layer, fieldName); if (field) { codedValueDomain = field.domain; } } if (codedValueDomain) { if(codedValueDomain.type === 'codedValue'){ for (var cv = 0; cv < codedValueDomain.codedValues.length; cv++) { var codedValue = codedValueDomain.codedValues[cv]; if (fieldValue === codedValue.code) { result = codedValue; break; } } } } return result; }
,
Another way to do this , in the query task result you can find the field information including domain information if the field is assigned to domian, Then you can get each coded domain value and update the query result with domain instead of the code.
var domain = queryResults.featureSet.fields["Your Field Index"].domain;
var codedValues = domain.codedValues;
Roxanne,
Are you developing a JS app or something in WAB?
If it is for Native JS API app then you just need to change the function signature to this:
function _getCodedValue(layer, fieldName, fieldValue, typeID) {
Then in your code use the function by providing the appropriate function parameters
var codedValue = _getCodedValue(yourlayerobject, "your field name", theCurrentFieldValue, theTypeIDifyourfieldusesasubtype);
Robert,
I was going to try using this code snippet in my existing code. As I've got zero coding experience and this is my first web map, I'm not sure what text do I change in your snippet and to what to make it work with my data. I have a field called Make, that has a domain applied to it called CCTVmakes. It's setup so 1=Make X and 2= Make Y, etc...
Thanks.
Thanks Robert. Works for my needs.
Billy
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.