Select to view content in your preferred language

Arcade: Display value(s) when not Null. If no value, display nothing.

4671
5
Jump to solution
01-22-2024 02:22 PM
JaredPilbeam2
MVP Regular Contributor

In the new Map Viewer, I have one simple hosted feature layer with 15 features. The fields I'm concerned with could have none or up to seven values, respectively. I'm attempting to build an Arcade expression that displays the value when there is one (or many). And when there is no value, display nothing.

For example, the first highlighted row (Wheatland) has no values, whereas the second highlighted row (Will Ride) has seven.

JaredPilbeam2_2-1705961964116.png

The following works to get me the first value to display in the popup when there is one. I don't know how to properly display many.

Attribute expression:

var tp = $feature.Township
return IIf(IsEmpty(tp),"none", "block")

Popup HTML:

<p style="display:{expression/expr8};">
    Township: {Township}&nbsp;<br>
    &nbsp;
</p>

 

Ideal scenario:

In the map, if I were to click the Wheatland polygon, I would see nothing. And if I clicked the Will Ride poly I would see: Township: Crete, Frankfort, Green Garden, Monee, Peotone, Washington, Will

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

This code will return the list of townships, leaving out the blank ones.

 

Expects($feature, 'Townshi*'); //Requests all fields beginning with "Townshi" 
var fieldArr = ['Township','Township2','Township3','Township4','Township5','Township6','Township7'];
var output = [];
for (var index in fieldArr) {
  if (!IsEmpty($feature[fieldArr[index]])) Push(output, $feature[fieldArr[index]])
}
return Concatenate(output, ", ")

 

 

 

View solution in original post

5 Replies
KenBuja
MVP Esteemed Contributor

This code will return the list of townships, leaving out the blank ones.

 

Expects($feature, 'Townshi*'); //Requests all fields beginning with "Townshi" 
var fieldArr = ['Township','Township2','Township3','Township4','Township5','Township6','Township7'];
var output = [];
for (var index in fieldArr) {
  if (!IsEmpty($feature[fieldArr[index]])) Push(output, $feature[fieldArr[index]])
}
return Concatenate(output, ", ")

 

 

 

JaredPilbeam2
MVP Regular Contributor

That's it! Thanks a lot. I see I do not need to include the HTML as the expression works like I expect on its own. The only thing is how to somehow work the string "Township: "  into the expression.

0 Kudos
SimonCrutchley
Frequent Contributor

Hi folks, I'm trying to do something similar in the pop-up. I want to display a bit of text with the link to a report, where one exists, but leave it completely blank where there isn't one. I assumed I could do this with the add 'Arcade' element to the pop-up, but although I have written a bit of code which returns the correct value in the test area, it doesn't work when live. Have I misunderstood how this works? I should add that I'm new to Arcade, beyond the simple stuff in Pro. Happy to share some sample data etc. if necessary. Ta

0 Kudos
KenBuja
MVP Esteemed Contributor

I would suggest opening a new question on this and provide the code that you've tried.

0 Kudos
SimonCrutchley
Frequent Contributor

Okay. Will do.

Ta

0 Kudos