arcade output the field name alias

165
4
Jump to solution
2 weeks ago
AngeliaH
New Contributor II

Hello!  I am trying to return the alias field name rather the the actual field name for a pop-up in a hosted feature layer in Arcade.  Basically I am searching my feature layer for any field that has the value "Yes" and want to return a list of fields.   I am trying to use the schema function but keep getting a syntax error.  Does anyone have any ideas on what I am doing wrong?

// Create a featureset, my layer is called ParkRecreationFacilities
var features = FeatureSetByName($map,"Park_and_Recreation_Facilities_public - Park and Recreation Facilities", ['*'], 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;

//Create output variable that will pull alias field name
var output = aDict2["alias"];

var returnstring = "Yes"
for (var i in $feature) {
     if ($feature[i] == returnstring) {
          output += i + TextFormatting.NewLine;
     }
}
return output

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Honored Contributor

What's happening is your var output line is failing since it's not a dictionary, but an array of dictionaries. You have to cycle through each of them to get the correct alias.

Here's one way to show the alias

 

var features = FeatureSetByName($map, 'your layer', ['*'], false);
var aDict = Schema(features);
var aArray = aDict["fields"];
var output;
for (var i in $feature){
  if ($feature[i] == 0) {
    for(var j in aArray) {
      var dict = aArray[j];
      if (dict['name'] == i){
        //console(dict['alias']);
        output += dict['alias'] + TextFormatting.NewLine;
      }
    }
  }
}
return output;<code></code><code></code>

 

Note: ignore the code stuff after "return output:". Something odd is going on with the parser.

 

View solution in original post

0 Kudos
4 Replies
AngeliaH
New Contributor II

I've also tried this syntax:

var output = ''
var returnstring = "Yes"
for (var i in $feature) {
    if ($feature[i] == returnstring) {
        output += Schema(i)["alias"] + TextFormatting.NewLine;
    }
}
return output

I feel like I am so close to figuring it out...

0 Kudos
KenBuja
MVP Honored Contributor

What's happening is your var output line is failing since it's not a dictionary, but an array of dictionaries. You have to cycle through each of them to get the correct alias.

Here's one way to show the alias

 

var features = FeatureSetByName($map, 'your layer', ['*'], false);
var aDict = Schema(features);
var aArray = aDict["fields"];
var output;
for (var i in $feature){
  if ($feature[i] == 0) {
    for(var j in aArray) {
      var dict = aArray[j];
      if (dict['name'] == i){
        //console(dict['alias']);
        output += dict['alias'] + TextFormatting.NewLine;
      }
    }
  }
}
return output;<code></code><code></code>

 

Note: ignore the code stuff after "return output:". Something odd is going on with the parser.

 

View solution in original post

0 Kudos
AngeliaH
New Contributor II

Yes!  Thank you!  I had to tweak 1 little thing and it works!  Hooray!  Here is the final syntax:

var features = FeatureSetByName($map, 'Park_and_Recreation_Facilities_public - Park and Recreation Facilities', ['*'], false);
var aDict = Schema(features);
var aArray = aDict["fields"];
var output;
for (var i in $feature){
    if ($feature[i] == "Yes") {
        for(var j in aArray) {
            var dict = aArray[j];
            if (dict['name'] == i){
                output += dict['alias'] + TextFormatting.NewLine;
            }
        }
    }
}
return output;

0 Kudos
KenBuja
MVP Honored Contributor

Great! That one tweak was left over from testing with my data.

0 Kudos