2

I'm trying to return certain fields in my popup in AGOL depending on the value in the visit type field. I'm struggling to figure out how to return the alias field name and value. Right now my expression only returns the field name. Any suggestions?

var list1 = ['COMNAME','ABUNDANCE']
var list2 = ['CLASS']
for (var i in $feature) {
    if ($feature.VISITTYPE == 'Mapping') {
        return list1;
    }
    else if($feature.VISITTYPE == 'Treatment'){
        return list2
    }
}

Current results in popup:

 - COMNAME
 - ABUNDANCE

If I change list1 to :

var list1 = [DomainName($feature,"COMNAME"), DomainName($feature,"ABUNDANCE")]

Then I get the values now but without the field alias name:

- Black mustard
- Linearly Scattered

My desired results in popup is below:

   Common Name: Black mustard
   Abundance: Linearly Scattered

2 Answers 2

1

The Alias is NOT a domain, a domain is a look up value, so you might be storing "BM" in the field but that looks up in the domain as "Black Mustard". Domains are for quality control and storing data efficiently.

The fields alias is part of the dataset structure, often referred to as the schema. So you need to be reading the schema.

This makes the Arcade code in the pop-up much more complex. I provide the code below:

// Create a featureset, my layer is called test2
var features = FeatureSetByName($map,'test2', ['*'], false);

// Create a dictionary holding the schema
var aDict = Schema(features);

// Create an array of dictionary's holding field info
var aArray = aDict["fields"];

// Access dictionary directly for field position 1
var aDict2 = aArray[1];
var myText1 = aDict2["alias"] + ": " + $feature.COMNAME;

// Access dictionary directly for field position 2
var aDict2 = aArray[2];
var myText2 = aDict2["alias"] + ": " + $feature.ABUNDANCE;

// Construct pop up text
var myText = myText1 + TextFormatting.NewLine + myText2;
return myText;
0

For anyone else who's looking, here's what I've got to get the alias name based on the field name for any field in your dataset:

// Create a FeatureSet using the appropriate FeatureSetByName/Id
// get all fields (['*']), no gemoetry (false)
var features = FeatureSetById($datastore, /* layer id */ '0', ['*'], false)
var schema_dict = Schema(features);
var fields_array = schema_dict['fields'];

function GetAlias(fieldname, fields_array){
    for(var i in fields_array){
        if (fields_array[i]['name'] == fieldname){
            return fields_array[i]['alias'];
        }
    }
    return fieldname;
}

// Build a string from all the fields and their values
var out_string = ''
for (var field in $feature){
    var alias_name = Proper(GetAlias(field, fields_array))
    out_string += TextFormatting.NewLine + alias_name + ': ' + TextFormatting.NewLine + '—   ' + $feature[field]
}
return out_string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.