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
Solved! Go to Solution.
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.
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...
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.
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;
Great! That one tweak was left over from testing with my data.
Hi everyone,
I'm not an expert with Arcade I'm looking for help to slove a problem
So I'm using this code to hide on popups the null fields is it working but I would like to change the "field name" to the "field alias"
This is a related table but i think there's no problem with that.
Thank you all! 😄
var skipFields = ['Creator', 'CreationDate', 'Editor', 'EditDate', 'OBJECTID', 'GlobalID'];
var allFields = '';
for(var i in $feature){
var skip = False;
for(var j in skipFields){
if(Text(i) == Text(skipFields[j])){
skip = True;
}
}
if(isEmpty($feature[i])){
Console(Concatenate('Null Field: ', i));
} else if (skip){
Console(Concatenate('Skipping Field: ', i));
} else {
Console(Concatenate('Including Field: ', i));
allFields = Concatenate([allFields, Upper(i), TextFormatting.NewLine, Text($feature[i]), TextFormatting.NewLine, TextFormatting.NewLine]);
}
}
Console(allFields);
return allFields;