I have a country table where some attribute data where some of the complete data fields are applicable and some are not so the field is blank <Null>. For example, tick-borne encephalitis in only applicable in 10 countries so it is blank in the other 242 countries. How to I configure a popup in AGOL to display the field (tick-born encephalitis) when data is present and not display it which the field is empty?
It seems that three statements are needed to get this done. I went to the ArcGIS Online guys at UC and we came up with the following 3 scripts. What I'm looking for is a wild card to add to the $feature.[field] so the script would roll through the list of values in the popup and display only those fields which are not null. It would seem the addition of a wildcard would allow this to happen in the $feature.field.
Any other thoughts?
Creates the label
if (IsEmpty($feature.Field1)){
return ""
} else {
return "Field 1"
}
Returns Field 1 value
if (IsEmpty($feature.Field1)){
return ""
} else {
return $feature.Field1
}
Converts to URL
if (IsEmpty($feature.Field1)){
return ""
} else {
return "Field2"
}
I managed to find a workaround that worked for me. I had a set of parks with Yes/No values on attributes like BASEBALL, FOOTBALL, etc. I wanted to show what are the available sports in every park, but without blank lines. So basically here are the steps :
Here is the code :
_________________________________
var arr = Split(
Concatenate(
IIf($feature.BASEBALL == 'Yes', ' • Baseball;', Null),
IIf($feature.BASKETBALL == 'Yes', ' • Basketball;', Null),
IIf($feature.FOOTBALL == 'Yes', ' • Football;', Null),
IIf($feature.SOCCER == 'Yes', ' • Soccer;', Null),
IIf($feature.TENNIS == 'Yes', ' • Tennis;', Null),
IIf($feature.VOLLEYBALL == 'Yes', ' • Volleyball;', Null)
),";");
var number = Count(arr);
if (number==1){
return '*** No sport in this park ***';
} else if (number==2){
return Text(Concatenate((arr[0]) + TextFormatting.NewLine + (arr[1])));
} else if (number==3){
return Text(Concatenate((arr[0]) + TextFormatting.NewLine + (arr[1]) + TextFormatting.NewLine + (arr[2])));
} else if (number==4){
return
...
...
} else {
return 'other';
}
I use the following for hiding non-null fields in Popups:
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;
It returns a basic output like this:
It does restrict the formatting of elements, but saves a lot of configuration as it can be used against any layer.
From my testing it does not display in Collector. I'm guessing it's because of the $feature reference, but haven't had a chance to look into it.
If you are worried about aesthetics, check out this blog. More work, but less raw!