Hello all,
I'm attempting to automatically compile an array of domain codes for comparison when deciding how to visualize a layer.
So this is what I've got so far:
var codearray = Array(1)
var domain = Domain($feature, "Status")
var index = 0
var codedValues = domain.codedValues[index].code
for(var att in codedValues){
Insert(codearray, 0, codedValues)
index + 1
}
return codearray
Results:
array(4)
0: null
1: "Run"
2: "Run"
3: "Run"
Input Data (results of Domain function)
dictionary
codedValues: array(2)
0: dictionary
code: "Run"
name: "Run"
1: dictionary
code: "Standby"
name: "Standby"
dataType: "esriFieldTypeString"
name: "HydrantLoc_111319_Status_f1dd7c78-d63c-4b23-8d0d-a5f5c916c584"
type: "codedValue"
The Results I'm looking for:
array(2)
0: "Run"
1: "Standby"
Then to take this a step further I'm looking to do this for multiple fields and then combine them into another array that contains every combination of value from each array. But maybe that's a problem for a different post.
Thanks In Advance Yall!
Solved! Go to Solution.
You can use the Schema function to get the domain information for all the fields. This code gives you an array of an array of the fields and their codedValue domain names.
var dict = Schema($feature);
var fieldsArray = dict.fields;
var domainsArray = [];
for (var i in fieldsArray) {
if (HasValue(fieldsArray[i], 'domain')) {
if (HasValue(fieldsArray[i].domain, 'codedValues')) {
var domainArray = [fieldsArray[i].name]
for (var d in fieldsArray[i].domain['codedValues']) {
Push(domainArray, fieldsArray[i].domain['codedValues'][d].name)
}
Push(domainsArray,domainArray)
}
}
}
return domainsArray
You can use the Schema function to get the domain information for all the fields. This code gives you an array of an array of the fields and their codedValue domain names.
var dict = Schema($feature);
var fieldsArray = dict.fields;
var domainsArray = [];
for (var i in fieldsArray) {
if (HasValue(fieldsArray[i], 'domain')) {
if (HasValue(fieldsArray[i].domain, 'codedValues')) {
var domainArray = [fieldsArray[i].name]
for (var d in fieldsArray[i].domain['codedValues']) {
Push(domainArray, fieldsArray[i].domain['codedValues'][d].name)
}
Push(domainsArray,domainArray)
}
}
}
return domainsArray
That worked perfectly. Thanks for the help!