Is there a way to create one Arcade expression that could be applied across multiple attributes instead of creating an expression for each one?
Example:
I have a feature layer and it has, let's say, 20 attributes. If there is a NULL I want the pop up to display "No observations", and if there is data, display said data. Right now I currently have to make an Arcade expression for each attribute. Here is my expression;
Text(IIf(IsEmpty($feature.Est1), "No observations", $feature.Est1), '#,###')
Now instead of copying and pasting this expression 20 times and just changing what attribute it applies to is there a way to just do it with one? This also applies to Pro as well (Better Pop Up Arcade Expression?).
Any easier way to do it would be to change the data in Pro and have be text but then that throws a bunch of stuff off and that's a whole different topic. Thanks everyone!
Solved! Go to Solution.
Any HTML you generate in the expression will not be honored in the pop-up window.
An example of looping through multiple attributes:
var atts = [["Feature code", $feature.FEATURECODE],
["Floor count", $feature.FLOORCOUNT],
["Roof form", $feature.ROOFFORM],
["Roof direction", $feature.ROOFDIR]];
Console(atts);
var result = "";
for (var i in atts) {
Console(i);
var att = atts[i];
Console(att);
if (IsEmpty(att[1])) {
if (result == "") {
result = att[0] + ": " + "No information available";
} else {
result += TextFormatting.NewLine + att[0] + ": " + "No information available";
}
} else {
if (result == "") {
result = att[0] + ": " + att[1];
} else {
result += TextFormatting.NewLine + att[0] + ": " + att[1];
}
}
}
return result;
There are two ways you can do this:
You cannot create a single expression that takes a parameter so that a single expression can be used 20 times to create 20 different outputs.
How would I build an Arcade expression to iterate through the attributes? I am a little bit familiar with ArcPy (loops and Data Access Cursors) but not familiar with how to do this with Arcade. Also, with one expression it could be possible to build a custom pop-up table with HTML I would think.
Any HTML you generate in the expression will not be honored in the pop-up window.
An example of looping through multiple attributes:
var atts = [["Feature code", $feature.FEATURECODE],
["Floor count", $feature.FLOORCOUNT],
["Roof form", $feature.ROOFFORM],
["Roof direction", $feature.ROOFDIR]];
Console(atts);
var result = "";
for (var i in atts) {
Console(i);
var att = atts[i];
Console(att);
if (IsEmpty(att[1])) {
if (result == "") {
result = att[0] + ": " + "No information available";
} else {
result += TextFormatting.NewLine + att[0] + ": " + "No information available";
}
} else {
if (result == "") {
result = att[0] + ": " + att[1];
} else {
result += TextFormatting.NewLine + att[0] + ": " + att[1];
}
}
}
return result;
Sorry, I think I misspoke about the HTML portion. How I do it now is a build a bunch of Arcade expressions and then when I go to configure my pop-ups I select custom attribute display. In there I'll create my own display using HTML, not using HTML in the Arcade expression.
Actually, disregard my last comment. I'm testing out the expression you provided and now I understand what you are talking about. I think I can make this work. Thank you for your help!