Can i eliminate empty values using arcade in my pop up?

18068
18
05-08-2019 12:07 PM
KevinMilton
New Contributor III

I am attempting to create a conditional arcade expression that will list all of the fields that do not have a null value with an individual label and not show the field at all if the field is null. My current expression is below.

if (IsEmpty($feature.ABARTA_WI)){
return ""
} else {
return "Abarata: "+$feature.ABARTA_WI
}

This expression works in that it does not show the label or null value, but in the ArcGIS Portal pop up, it leaves an empty line for each one that is null, and i need it to not be there at all so the pop up is clean. As you can see below, this is creating empty lines in the popup. 

I would prefer the popup to display something like below, eliminating the empty lines.

Chief: 0.28

Chief WI MKR: 0.28

Enerplus: 0.3

arcade expression‌ arcade pop-ups‌conditional pop ups‌

Any help would be greatly appreciated.

Thank you

18 Replies
KevinMilton
New Contributor III

BUG-000122554

In Portal for ArcGIS Map viewer, an Arcade Expression to configure fields in a pop up does not honor the TextFormatting.NewLine

GeraldSneary
New Contributor III

Xander Bakker

I can write one-off conditional expressions but how do you combine multiple conditional expressions for different fields? In the example below Field 1 & 2 are from one layer and Field 3 is from the popup layer. I want to only return a value and if it is null do not return an empty space. I can write an expression for each field that is null and only return the other 2 or all 3 if all values are present but not how to combine all expressions.

 

Field1       Field1  or  Field2  or Field1  or Field3 and so on

Field2       Field2       Field3      Field3

Field3 

 

I know how to return all fields even if it's null but it leaves a space/s.

 

 

This is my expression:


var buildn = FeatureSetByName($map,"NLCOG Buildings",["BUILDING_N"])
var fsIntersectbuild = Intersects(buildn, $feature)
var fbuildn = first(fsIntersectbuild)

var buildu = FeatureSetByName($map,"NLCOG Buildings",["USAGE_"])
var fIntersectbuild = Intersects(buildu, $feature)
var fusage = first(fIntersectbuild)

var occp = $feature.OCCUPANCY

iif (fbuildn.BUILDING_N == null, fusage.USAGE_ + TextFormatting.NewLine + occp, fbuildn.BUILDING_N + TextFormatting.NewLine + fusage.USAGE_ + TextFormatting.NewLine + occp)
//iif (fusage.USAGE_ == null, fbuildn.BUILDING_N + TextFormatting.NewLine + occp, fbuildn.BUILDING_N + TextFormatting.NewLine + fusage.USAGE_ + TextFormatting.NewLine + occp)
//iif (occp == null || occp == 'SINGLEF', fusage.USAGE_ + TextFormatting.NewLine + fbuildn.BUILDING_N, fbuildn.BUILDING_N + TextFormatting.NewLine + fusage.USAGE_ + TextFormatting.NewLine + occp)

Each one of the iif statements works independently. I've tried using the When function but each field is different so it doesn't work or not the way that I wrote it.

Any help would be appreciated.

XanderBakker
Esri Esteemed Contributor

Hi Gerald Sneary 

I just answered your question at the Kelly's blog, but looking at the example pop-up, this is something that could be solved in the expression and has no need for table and rows.

Have a look at the following example:

var val1 = "A";
var val2 = Null;
var val3 = "Test";

var lst = [val1, val2, val3];
var result = "";
for (var i in lst) {
    If (!IsEmpty(lst[i])) {
        if (result == "") {
            result = lst[i];
        } else {
            result += TextFormatting.NewLine + lst[i];
        }
    }
}

Console("### start ###");
Console(result);
Console("### end ###");

return result;

This will write the following text to the Console:

### start ###
A
Test
### end ###

It will not create a line of the value is empty.

GeraldSneary
New Contributor III

Xander you are a lifesaver. Thank you so much!

My hunch was right a list was needed. I just started learning code a month ago. I was about to break out LP3THW and start looking at lists. But I know I wouldn't have come up with your syntax.

Too bad you don't live closer I'd take you out for a few beers.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi gerald.sneary80 ,

I'm glad to have helped. I also just posted a small document on how to hide rows in a table in case you need that:

Conditional Field display with Arcade in Pop Ups (with Arcade) 

SarahFox1
New Contributor III

How can this be done with hyperlinks?  I have a list of landmarks that have different types of websites for their documentation to relate back to.  The table method worked beautifully, until I added a hyperlink to each one, then it spaced everything out again.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi sjohnson_CityofLubbock ,

Is it possible to share the expression you have so far and he configuration of the pop-up?

0 Kudos
SarahFox1
New Contributor III

I actually figured it out based on an article of yours I found combined with another article!   It was really easy to follow and now my popups look spectacular!  Thank you!
Conditional Field display with Arcade in Pop Ups (revisited) 
Hyperlink within expression of pop-up in AGOL 

This is the expression I ended up using:
IIF(isEmpty($feature["NRHP_Site"]),"none", "National Register of Historic Places");

And the table HTML:

<tr style="display: {expression/expr8}">
<td><a href="{NRHP}">National Register of Historic Places</a></td>
</tr>

When I went to copy it though - it had changed to this:

<tr style="display: {expression/expr1}">
<td><a>National Register of Historic Places</a></td>
</tr>

So that's a bit wierd.

XanderBakker
Esri Esteemed Contributor

Hi sjohnson_CityofLubbock ,

The most important thing is that you made it work. But indeed, it is strange that it would change after copying. Let me know if you run into any problems and we'll see if we can figure it out.

0 Kudos