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

7324
16
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

16 Replies
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