Select to view content in your preferred language

How to hide blank field in AGOL

10332
13
06-20-2017 08:32 AM
by Anonymous User
Not applicable

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? 

Tags (1)
13 Replies
by Anonymous User
Not applicable

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"
}

GeoffroyRicher-Lalonde1
New Contributor

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 :

  1. Convert the Yes/No values into strings and null values with IIf statements, but add a separator ( like ; )
  2. Concatenate into a big string
  3. Split the big string into an array using the separators used in step 1
  4. Count the number of sports for each park
  5. Use some if/else if conditions to concatenate everything nicely (with new lines) for each specific number of sport.

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';
}

MikieKelly
Occasional Contributor

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!

0 Kudos
BrunoRochaPA
New Contributor

Hi everyone,

I'm a beginner with Arcade, im trying to hide a blank fields on popups of a related table on AGOL, to visualize them on "details" - dashboad widget I would appreciate a lot your help and tips! 😄 

0 Kudos