Select to view content in your preferred language

Conditional Field display with Arcade in Pop Ups

84765
118
07-18-2017 11:53 AM
KellyGerrow
Esri Alum
42 118 84.8K

The June 2017 Release of ArcGIS Online enabled the capability to write custom Arcade expressions for use in Pop Ups!! A common request was to be able to format pop ups to display attribute values and labels when values are present and not have them appear when the values are blank. Although there are plans to incorporate this functionality directly into the pop up in the future, it is currently possible to use Arcade and Custom Attribute Displays to accomplish this.

I'm going to use an existing example of my Heron Watch Data and display the description when one is present. I will hide the field value and field label when it isn't present. View the Heron location in Singapore to see a feature with no description, or add features using this GeoForm App with no description.  

Check out the steps below to accomplish this and then share your real examples!

Step 1: Create an Arcade Expression that tests for values using IsEmpty. This will be used to determine if the label for the attribute needs to be displayed or not. 

Sample code:

    IIF(isEmpty($feature.description), "", "Description")

If the feature is empty, a blank value will be returned. If there is a value, the label "Description" will be returned in the expression.

2. Configure a table using Custom Attribute Display in the pop ups that is configured to use the expression as the label.

        Custom Attribute

    - Enable the option to view Source HTML:

    

- Create a table using the HTML  sample below. The text in curly brackets refer to attribute values in the feature layer. The plain text between the first table elements specifies the label for each attribute.

<table cellpadding="0px" cellspacing="3px">
     <tbody>
           <tr valign="top">
               <td><b>Observed Time (UTC)</b></td>
               <td><span>{viewed}</span> 
               </td>
            </tr>
            <tr valign="top">
               <td><b> Observed Time (Local) </b></td>
               <td>{textviewed}</td>
            </tr>
            <tr valign="top">
              <td><b>Species</b></td>
              <td>{type_of_heron}</td>
            </tr>
           <tr valign="top">
               <td><b>{expression/expr0}</b></td>
               <td>{description}</td>
           </tr>
      </tbody>
</table>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

- Note that {expression/expr0} is the value of the Arcade expression created in Step 1 that is used for the attribute label and the description value is used for the value. If no value is present in the description there will also be no value for the label.

- Unselect the HTML Source option and your formatted pop up configuration should look similar to this screen shot:

3. Save your Web Map and make an app to show off your Pop Ups

Description Values Present:

Description Values not Present

If you don't want to use a table to display your attributes, consider integrating this workflow with free text and calculated Arcade Expressions as outlined in this blog by Bernie Szukalski:

https://blogs.esri.com/esri/arcgis/2015/12/28/custom-attribute-display-pop-ups/ 

118 Comments
deleted-user-292P7gV7eVle
Deactivated User

Hi,

Gerry Kelly‌, does this solution work with only popups that are custom made or is there a way to hide fields with a popup, which displays a list of field attributes (not using any HTML)?

XanderBakker
Esri Esteemed Contributor

Arcade expression configured in the pop-up will always add something to the pop-up and never hide. To hide fields just go into the configure attributes in the pop-up configuration and switch off the field you don't want to show in the pop-up:

deleted-user-292P7gV7eVle
Deactivated User

Thank you, Xander and yes, I'm aware of this solution  But I'm interested in conditionally hiding the field without using custom attribute display. 

XanderBakker
Esri Esteemed Contributor

You wont be able to do this using Arcade, The options I mentioned is how yo can do this. Can you explain a little more why you don't want to use custom attribute display or can't switch the fields off? 

JonathanSkloven-Gill
Regular Contributor

I have been using this method to list which related table a feature belongs to. I have a series of different types of street upgrades (lines, points, polys), and 9 different tables representing different research/demonstration events. Everything works GREAT! 

Until I save, and refresh the screen.

The custom attribute HTML block DELETES ALL of the Line Break conditionals:  <br style="display:{expression/expr1}" /> 

So now I have exactly what I was hoping to avoid: series' of blank lines in my pop up. ESRI, do you know of this 'bug'?

Here is a copy of the code block before reload (works perfectly in the pop-up windows)

<br style="display:{expression/expr1}" /><span style="display:{expression/expr1}">Streets Alive (2018)</span>
<br style="display:{expression/expr2}" /><span style="display:{expression/expr2}">Streets Alive (2019)</span>
<br style="display:{expression/expr3}" /><span style="display:{expression/expr3}"> SRTS with Dan Burden </span>
<br style="display:{expression/expr4}" /> <span style="display:{expression/expr4}"> SRTS Action Plan </span>
<br style="display:{expression/expr5}" /> <span style="display:{expression/expr5}"> Walkshop with Dan Burden </span>
<br style="display:{expression/expr6}" /> <span style="display:{expression/expr6}"> 2011 TSP </span>
<br style="display:{expression/expr7}" /> <span style="display:{expression/expr7}">Urban Renewal Plan </span>

Then, I save and reload the map window and it is now like this:

<br /><span style="display:{expression/expr1}">Streets Alive (2018)</span>
<br /><span style="display:{expression/expr2}">Streets Alive (2019)</span>
<br /><span style="display:{expression/expr3}"> SRTS with Dan Burden </span>
<br /> <span style="display:{expression/expr4}"> SRTS Action Plan </span>
<br /> <span style="display:{expression/expr5}"> Walkshop with Dan Burden </span>
<br /> <span style="display:{expression/expr6}"> 2011 TSP </span>
<br /> <span style="display:{expression/expr7}">Urban Renewal Plan </span>

Every time.

RachelGuinn
New Contributor

I am still having trouble trying to make empty fields NOT show up on my map, i've been trying to write this custom expression 

if (IsEmpty($feature.value))return none? or should i say return to the next value?! help!

XanderBakker
Esri Esteemed Contributor

I did a little test and what you could do is this a html code:

<span style="display:{expression/expr1}">Streets Alive (2018)</span>
<span style="display:{expression/expr2}">Streets Alive (2019)</span>
<span style="display:{expression/expr3}">SRTS with Dan Burden</span> 
<span style="display:{expression/expr4}">SRTS Action Plan</span>
<span style="display:{expression/expr5}">Walkshop with Dan Burden </span>
<span style="display:{expression/expr6}">2011 TSP</span> 
<span style="display:{expression/expr7}">Urban Renewal Plan</span>

The expression should return "none" in case you want to hide it and "block" in case you want to show the content. When I create expressions that return "block" for expression 1 and 7 and "none" for the rest, it shows like this:

XanderBakker
Esri Esteemed Contributor

Your custom HTML code should look like this:

<span style="display:{expression/expr0}">Your description: {YourFieldName}</span>

The expression should be something like this:

IIF(IsEmpty($feature.YourFieldName), "none", "block");
MichaelWoodward
Regular Contributor

I'm having a hard time either understanding the concept, or writing the expression.  

I have a map of our town that shows different water rates for the area.  There are two special water/sewer districts where we charge franchise fees.  I have fields for the rate code, water district name, and the franchise fee.  There's also a link to the policy that explains to customer service how to set up the customer.

For 90% of customers, all that needs to pop up is the Rate Code.  If they are in a special district, I want all of the fields to show up

I used the expression here: IIF(isEmpty($feature.District), "", "District")  "District" is the name of the field.  I created an expression similar to the first one for the other field.  I must be doing something wrong because if there is nothing in the field for a selection, it just shows up as blank space in the pop-up.

I would really like things to show up similar to the images below.  Right now, there are two different layers.  I would like everything to be on one layer.  If they're not in a special district, they would just get the water rate.  If they are in a special district they would get all the info below, just in one pop-up

DougBrowning
MVP Esteemed Contributor

I have tried all these different ways and still cannot get a URL to show.  

In my Arcade I do a lookup and get back a URL.

But in the popup I get nothing. Link1

Weird is that if I do this it works. Link2

Why? If I return the text URL it works but if I return from a feature it does not work.

And even weirder is we used to be able to just turn on the related table field that has this URL and it just worked with the More Info showing.  Then it stopped working for no reason and is now blank all the time.  We even had one service that worked and one that would not.  We must have published 100 times looking for a pattern.  Sometimes it was globalid on or off.  So I created Arcade and that is blank also.  I did a all new map.  

Not sure what is going on here but its driving us nuts that it works sometimes and not others.

I also tried this and still nothing.

return Text(first(tbl)["PhotoLink"])

Going crazy over here.  What could cause it to sometimes show More Info and be a working link and other times I just get blank.

Thanks!

DougBrowning
MVP Esteemed Contributor

We also just found out that our workaround to the (relationship/0/photolink) we used Arcade.  Well it turns out that if you have ANY Arcade expression in a map the Query Widget will break.  Even if that Arcade is on a different layer than the layer you Query!  Even if the expression is turned off in Config Attributes.  You must delete ALL Arcade in the entire map!

See here  https://community.esri.com/message/869526-re-query-widget-works-while-in-dev-mode-but-not-in-the-app... 

So many bugs...  

So how can I just get a simple photo link to appear?

Thanks

DougBrowning
MVP Esteemed Contributor

Also none of the relationships attributes will show now at all.  Just blank.

XanderBakker
Esri Esteemed Contributor

Hi Doug Browning ,

I have seen your questions and observations and I am wondering, did you report this to support? I have not seen this behavior that you are experiencing, but if it is happening to you, you might want to reach out to support for this. Creating an URL should normally work. You do not need to use the Text function, since your field will already be a text. You can also try using a custom HTML pop-up and insert the expression in the href attribute of an anchor (as a last resource).

If the Query widget really breaks any time you have a Arcade expression in the map, that would be a bad thing and really something you should report to support. I do see in the thread you link to, that this is related to the Dev edition of the WAB. I assume you are using the latest version?

DougBrowning
MVP Esteemed Contributor

Thanks Xander.   We confirmed these bugs in both the AGOL builder and the download WAB.  We used the latest of both.  I just added the text as a test since it makes no sense.  Plus I am only doing this to try to get around the relationship attributes bug.

I am a government contractor and do not have any access to call support.  Even if a did it would only confirm the bug but not fix it.  When I have had support access I racked up 10+ bugs and none of them have been fixed - with some over 5 years old now.  I have had better luck reaching out here in the hopes that someone has some connections to the right people.

The hard part for us is when it works then it does not.  Makes us look like we do not know what we are doing in front of our customers causing a hit to our reputation.  Honestly between AGOL and 123 bugs we are close to having to stop recommending Esri products.  We lost close to 40 hours of labor on just this one Arcade bug - the week we were going to launch.

Here are just some of the bugs we are fighting.

-Export to CSV in attribute table stopped working 
-All relationship class fields stopped working in pop ups - we were using this for months and even have screen shots of it working.  This one is big and should be hotfixed.
-If a field has a range domain that goes from 0 to whatever, if there is a 0 record it shows as 0 in the ArcGIS Online table, it shows as 0 in the popup, but null in the attribute table and when exported- we opened this bug in November of 2017.  We actually talked to someone at Esri on the phone.. and then got ghosted.
-And of course the Arcade breaks the query widget.  Plus we just found out from another team that any Arcade also breaks the Search widget (this one has been open since Jan 2019).

-Charts do not work right in popups.  This we got as BUG-000104430 - been open since 4/10/2017

Again thanks and I appreciate your time but support has not been working for getting things fixed so at this point it just adds on to the labor cost.  We just have to move on.

KyleCrawford2
Regular Contributor

I'm trying to incorporate this method to work with formatting a table that includes background-color for each cell below is the HTML pop up code

<table style="width:100%"><tbody><tr><th colspan="2"><b><font size="2"><br />City Material Data</font></b></th>
</tr>
<tr>
<td style="text-align: left;background-color: #ede8e8; padding: 5px">ID</td>
<td style="text-align: left;background-color: #ede8e8;padding: 5px"><span style="display:{expression/expr1}"> {Facility_Identification_No}</span><br />
</td></tr><tr>
<td style="text-align: left;background-color: #ede8e8; padding: 5px">Contact Person</td>
<td style="text-align: left;background-color: #ede8e8;padding: 5px"><span style="display:{expression/expr2}"> {Facility_Contact_Person}</span><br /></td>

</tr></tbody></table>
‍‍‍‍‍‍‍‍

Display for populate fields:                                  Display for empty fields:

 

Example of attribute expression: IIF(IsEmpty($feature["Facility_Identification_No"]), "none", "block");

My goal is for there to be no rows present when the attribute field is empty. Has anyone tried this out before?

XanderBakker
Esri Esteemed Contributor

Hi K_Crawford , 

Your <span> tag should enclose the entire table row "<tr>" to hide it. Not just the content of the cells.

KyleCrawford2
Regular Contributor

Hi Xander Bakker,

Do you mean like the following:

<table style="width:100%"><tbody><tr><th colspan="2"><b><font size="2"><br />City Material Data</font></b></th>
</tr>

<span><tr>
<td style="text-align: left;background-color: #ede8e8; padding: 5px">ID</td>
<td style="text-align: left;background-color: #ede8e8;padding: 5px"><span style="display:{expression/expr1}"> {Facility_Identification_No}</span><br />
</td></tr></span>

<span><tr>
<td style="text-align: left;background-color: #ede8e8; padding: 5px">Contact Person</td>
<td style="text-align: left;background-color: #ede8e8;padding: 5px"><span style="display:{expression/expr2}"> {Facility_Contact_Person}</span><br /></td>

</tr></span></tbody></table>
XanderBakker
Esri Esteemed Contributor

Hi Kyle Crawford ,

That is correct but the span should have the arcade expression none or block to hide or show the row.

CPoynter
Frequent Contributor

Hi,

Using the table format and arcade expressions, is it possible to not have empty spaces in a pop-up. For example, if I have values A, B, and C. If they all list for one point, but B and C are present for the next point, can I remove the table row for A to be replaced with B as the top row in my pop-up. I am trying to alleviate a messy pop-up with empty rows in the presentation of data.

SiranErysian2
Occasional Contributor

Hi,

This is similar to what I want to do in my Collector app. I need to write a statement that would force the user (or a message would pop up) to enter a value in a field if another field is or is not populated. For example, if a  field  for a measurement is left blank, then there must be a reason and that means the NM or No measurement field must be populated. this is a domain drop down selectable field. ( I can't seem to add a screen shot so may have to create a new question) . Also, if in the drop down field is equal to a certain value (0, 6, or 7) then a pop up would appear that instructs the user that another field (comments) must be filled in. It can't be that difficult but I have zero experience with writing Arcade expressions so any help is much appreciated!

JoeStefanoni
Occasional Contributor

Thanks!  That's exactly what I wanted to be able to do.

JoeStefanoni
Occasional Contributor

This is definitely helpful in that I am now able to exclude null values for a particular field from displaying in the pop-up but I have not been able to figure out how to tweak it so that I can also include the field name in the pop-up display when the value is not null?  If I add it prior to the NPL_STATUS field (NPL STATUS:), I get the field only showing up when the value is not null (which is what I want) but I get the field name (NPL Status: ) showing up in all the pop-ups, for when the value is null and not null:

<td><b>{expression/expr0}</b></td>
               <td>NPL Status: {NPL_STATUS}</td>

 

CPoynter
Frequent Contributor

Hi Xander,

Trying to hide empty records also.

My Arcade expression is:

{expression/expr3} = IIf(isEmpty($feature.USER_CSU_1),"none","block");

My custom HTML is:

<div style="padding:5px;background-color:rgb(199,184,160)"><b>Scholarships Test:</b></div>
<table style="width:100%;">
<tbody>

<span style="display:{expression/expr3}>
<tr>
<td><a href="{USER_CSU_1}" target="_blank">{expression/expr0}</a><br /></td>
</tr>
</span>

</tbody>
</table>

Not sure of the correct structuring to hide my empty fields and subsequently hide their rows.

Craig

GeraldSneary
Occasional Contributor

Kelly Gerrow

Xander Bakker

Kevin MacLeod

I can write one-off conditional expressions but how do you combine multiple conditional expressions for different fields? I have 3 fields I want to return to a new line but only if there is a value to return. Example:

Field1  or  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 an empty space.

Field1

Field3

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 ,

How are you displaying the resulting values? Are you using any custom HTML? If you simply want to put each value on a new row you can have a single expression that will do that.

This thread is focused on configuring HTML to conditionally show rows of a table using Arcade. Have a look at the HTML below:

<table><tbody>

  <tr style="display:block">
    <td style="width:125px; text-align:left; background-color:#ede8e8; padding:5px">row 1</td>
    <td style="width:225px; text-align:left; background-color:#ede8e8; padding:5px">value 1</td>
  </tr>

  <tr style="display:none">
    <td style="width:125px; text-align:left; background-color:#ede8e8; padding:5px">row 2</td>
    <td style="width:225px; text-align:left; background-color:#ede8e8; padding:5px">value 2</td>
  </tr>

  <tr style="display:none">
    <td style="width:125px; text-align:left; background-color:#ede8e8; padding:5px">row 3</td>
    <td style="width:225px; text-align:left; background-color:#ede8e8; padding:5px">value 3</td>
  </tr>

  <tr style="display:block">
    <td style="width:125px; text-align:left; background-color:#ede8e8; padding:5px">row 4</td>
    <td style="width:225px; text-align:left; background-color:#ede8e8; padding:5px">value 4</td>
  </tr>

</tbody></table>

On lines 3 and 18 the table row (tr) has a style defined as "display:block", while on lines 8 and 13 the style is defined as "display:none". This results in only showing row 1 and 4 as you can see below:

 

In your case you will have an expression for each field, just to determine if it should display or hide and one for the actual value to display. In case of 3 fields, this will result in 6 expressions. I notice that your expression contains various intersects and access to other feature sets. Doing this 6 times just to conditionally display the rows, will result in poor performance. 

In ArcGIS Pro you can actually output HTML, so you would only need a single expression and a lower number of requests to the server and hopefully this will be supported by the web map soon.

JoeStefanoni
Occasional Contributor

It took some time to get it wright, but this works like a charm:

For the layer, select configure pop-up, then Display a custom attribute display and switch to HTML. Then enter the following HTML Code for each layer where you want to exclude Null values:




**NPL is the name of the field I want to exclude Null values for

You will also need to add the following Attribute Expression:

IIF(isEmpty($feature.NPL), "none", "inline")

Continue to do this in both sections for each field you want to exclude Null values for. Only the name of the field and expr number will change in the HTML:


And only the field name will change in the attribute expression:

IIF(isEmpty($feature.CHROME_SITE), "none", "inline")

You’re attribute expression ox will look something like this when done (I set up 6 expressions):

Good luck,

Joe

Joe Stefanoni, GIS Specialist

NJDEP – Site Remediation Program

(609) 633-1405

joe.stefanoni@dep.nj.gov<mailto:joe.stefanoni@dep.nj.gov>

XanderBakker
Esri Esteemed Contributor

Hi Craig Poynter ,

I just saw that you mentioned me (unfortunately you did not tag me). If you still have this problem you might want to have a look at this document I just posted: https://community.esri.com/docs/DOC-14276-conditional-field-display-with-arcade-in-pop-ups-with-arca... 

CPoynter
Frequent Contributor

Hi Xander Bakker,

Yes I was able to solve my issue.Thank you for responding.

Regards,

Craig

JoannaHahn
Emerging Contributor

Kelly this article was so helpful. I'm trying to incorporate a concatenate expression into the iif statement so I can include a unit of measure on the field to display if the first statement is true. But the result is the unit of measure is present in my pop up regardless if the field is empty in my other expression using isempty. Any ideas what I'm doing wrong? Here is my expression, it works as you described if I don't use concatenate. But I don't see why I shouldn't be able to.

iif($feature["Arsenic_Function"]>=$feature["Arsenic_MCL"],concatenate([$feature["Arsenic_ug_L_"], "ug/L"], " "), "")

Thank you!

XanderBakker
Esri Esteemed Contributor

Hi jhahn_dhw2 ,

Since your expression is using 3 fields, I'm not sure which field needs to be checked if it is empty. I assumed it is "Arsenic_ug_L_". If so, can you try this?

if (IsEmpty($feature["Arsenic_ug_L_"])) {
    return "";
} else {
    iif($feature["Arsenic_Function"]>=$feature["Arsenic_MCL"],
        concatenate([$feature["Arsenic_ug_L_"], "ug/L"], " "), 
        "");
}
JoeStefanoni
Occasional Contributor

Try doing it without the concatenate command –

iif(($feature["Arsenic_Function"]>=$feature["Arsenic_MCL"]), [$feature["Arsenic_ug_L_"] + " ug/L"], "")

Joe Stefanoni, GIS Specialist

NJDEP – Site Remediation Program

(609) 633-1405

joe.stefanoni@dep.nj.gov<mailto:joe.stefanoni@dep.nj.gov>

JoannaHahn
Emerging Contributor

Thanks Xander!

Actually can I back up a few steps? I have three expressions:

1. If the value is less than a threshold:

{expression/expr1}=

iif($feature["Arsenic_Function"]<$feature["Arsenic_MCL"],concatenate([$feature["Arsenic_ug_L_"], "ug/L"]," "),"")

2. If the value is greater than or equal to a threshold:

{expression/expr0}=

iif($feature["Arsenic_Function"]>=$feature["Arsenic_MCL"],concatenate([$feature["Arsenic_ug_L_"],"ug/L"]," "),"")

3. If there is no value: 

{expression/expr2} =

iif(isempty($feature["Arsenic_ug_L_"]),"","Arsenic:")

And I've configured my pop up as follows:

Here are my results:

Good:

Good:

Bad:

Since the problem example is in orange, I'm assuming I have done something wrong with my expression/expr1 = iif($feature["Arsenic_Function"]<$feature["Arsenic_MCL"],concatenate([$feature["Arsenic_ug_L_"], "ug/L"]," "),""). It's not showing the Arsenic title that is expressed in the isempty expression which is good, but it's holding on to that concatenate field regardless if the $feature["Arsenic_ug_L_"] is null.

Thank you for your help!

JoeStefanoni
Occasional Contributor

See my last response. Maybe eliminating the concatenate command will work since you suggested that when you added the command, the pop-up stopped functioning properly.

I actually have a whole different way of displaying pop-ups/hiding null vales but it’s a little more complicated as it involves setting up an Arcade expression to display when values are present and not display nulls and then further manipulation of the expression via HTML in the pop-up configuration.

Joe Stefanoni, GIS Specialist

NJDEP – Site Remediation Program

(609) 633-1405

joe.stefanoni@dep.nj.gov<mailto:joe.stefanoni@dep.nj.gov>

JoannaHahn
Emerging Contributor

I did try that and same result. How can I learn more about your other approach? I could go back to my raw data and just add the unit of measure in the field but I don't want to give up. I don't see why I shouldn't be able to get something to work here. 

JoannaHahn
Emerging Contributor

I fixed it!

iif(isempty($feature["Arsenic_ug_L_"]),"",iif($feature["Arsenic_Function"]<$feature["Arsenic_MCL"],$feature["Arsenic_ug_L_"] + " ug/L",""))

Since I gave it a direction if a field was below another field, it saw null as below that field and therefore reported a null with the unit of measure. 

Thanks for your help!!

JoeStefanoni
Occasional Contributor

Awesome! Do you know how would you write an IIF expression to try and capture a numeric value between say 1 and 10?

Joe Stefanoni, GIS Specialist

NJDEP – Site Remediation Program

(609) 633-1405

joe.stefanoni@dep.nj.gov<mailto:joe.stefanoni@dep.nj.gov>

JoannaHahn
Emerging Contributor

I don't. Would love to learn!

MikieKelly
Occasional Contributor

If you're not worried about aesthetics and want a quick way to display non-null fields, you can use something like this:

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 without much effort. 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.

MarceloRosensaft
Regular Contributor

Hello,

My problem has been mentioned here but I couldn't find a solution.

I use an IF statement in Arcade to show different texts in my popup. I'd like to be able to introduce the hyperlink option into the IF so in one case it shows the text as a clickable hyperlink and in the other case it shows just text - no hyperlink attached to it and no option to click on it.

Thank you in advance,

Marcelo

XanderBakker
Esri Esteemed Contributor

Hi Marcelo Rosensaft ,

There is a way to do this, but it would use 5 (simple) expressions and HTML. You could use something like this in the pop-up:

<a href="{expression/expr0}" style="display:{expression/expr1}">{expression/expr2}</a><div style="display:{expression/expr3}">{expression/expr4}</div>

It consists of an anchor (html link) and a div element. Both can be provided with a display style setting that is either "none" (do not show) or "block" (show). Additionally you will have expressions that will contain the url, the explaining url text and the normal text.

{expression/expr0}
- Will return the URL when it is available or return an empty string

{expression/expr1}
- The expression to validate if the url should be shown
IIf(should display url, "block", "none");

{expression/expr2}
- the link text if the url is available o an empty string

{expression/expr3}
- expression to validate if the url should be shown (inverting true/false arguments)
IIf(should display url, "none", "block");

{expression/expr4}
- The normal text to display if the url is not available

Example when a link is available:

 

Example when no link is available

MarceloRosensaft
Regular Contributor

It worked perfectly. Thank you so much!

I have another little issue that Id like to fix. In the line with the hyperlink I'd like to have some regular text and then the text with the hyperlink. In the next line:

<a href="{expression/expr5}" style="display:{expression/expr6}">Map page: {expression/expr7}</a>

"Map page: " is the regular text and the "expr7" contains the text for the hyperlink. The result is that both "map page: " and the expr7 get the hyperlink.

The other option was to move the regular text ("Map page: ") out of the "<a... line" so it doesn't get the hyperlink but then the regular text is shown in a separate line, like:

Map page:

hyperlink text

Any way to solve it?

Thank you in advance!

XanderBakker
Esri Esteemed Contributor

Hi marcelorosensaft ,

Could you try this:

<div style="display:{expression/expr6}">Map page: <a href="{expression/expr5}">{expression/expr7}</a></div>

It places the text outside the anchor and everything inside a div that will either be visible or not.

Pauline_Low_Pui_Ling
Emerging Contributor

Hi Xander Bakker,

Wondering if the conditional colour mapping using Arcade Expression works on Explorer for you? As for my case, the arcade expressions for conditional colour mapping is not seen in the Explorer app. It only works in Web Map viewer..

Thanks,

Pauline

XanderBakker
Esri Esteemed Contributor

Hi Pauline Low Pui Ling ,

I just opened a web map that use Arcade to classify the age of hydrants and the expression works. In the pop-up I use FeatureSetBy* to retrieve the maintenance history and that part does not work. Can you share the Arcade expression you are using?

utenalarosa
Occasional Contributor

@XanderBakker 

Can anyone help me I am trying to hide empty fields both the Arcade expression and HTML script are right but they are not displaying the field names:

Arcade expression:

IIf(IsEmpty($feature["prop_id"]), "", "Property ID")

HTML

utenalarosa_0-1614876229852.png

pop up:

utenalarosa_1-1614876259139.png

 

XanderBakker
Esri Esteemed Contributor

Hi @utenalarosa ,

I have another post here: https://community.esri.com/t5/arcgis-online-documents/conditional-field-display-with-arcade-in-pop-u... where I explain how you can hide the entire row in a table when there is no information for that attribute. What you are trying to do is create an empty line (two empty table cells) and I don't think that will look very good. 

utenalarosa
Occasional Contributor

@XanderBakker 

If the field is empty I want that field to be skipped and write the next one which it does that like in the image below the prop_id field is empty so it's not displaying 

utenalarosa_0-1614877978907.png

while the one below has pro_id field

utenalarosa_1-1614878042000.png

what i am missing now is the field name or alias displaying before the information.

This what I get by following the link you sent me it's not hiding the prop_ID:

utenalarosa_0-1614879787394.png

 

Thanks,

Teresa

XanderBakker
Esri Esteemed Contributor

Hi @utenalarosa ,

Your formula should work. Can you check and see if the field really has a Null value or an empty string? If it contains as little as a single space the IsEmpty will return false. 

The same also applies to the link I shared earlier. If there is a space in the field it will not be empty and the row will be shown.

utenalarosa
Occasional Contributor

@XanderBakker 

It's is working in my code it's hiding the empty field but it doesn't work when I try following your link instructions, in my code what is not working is the fact that is not displaying the field name like in the example 

utenalarosa_0-1614885459851.png

where the red line are in the image below should say County: geo_id; prop_id; Owner name

utenalarosa_1-1614885635575.png

I try hard coding the field names in but then they still show Prop_id even when is the empty.

Thanks,

Teresa

XanderBakker
Esri Esteemed Contributor

Hi @utenalarosa ,

Is it possible to have access to the map and underlying data? I am pretty convinced that this is data-related, but without access, there is little that I can do. If you are able to share, please create a group, share the map and data to the group and invite me to it using my AGOL identity "xbakker.spx".

About the Author
I love interactive maps and apps on the internet! The maps and apps that customers create and share on the web, make my job awesome. I'm a Product Manager with the ArcGIS Online team in Redlands, California. I am a proud graduate from Carleton University and the COGS in Canada, with research focus' in Health Geography. Originally from Bedford, NS, Canada but have spent a lot of time in Haliburton and Ottawa, Ontario. I have a passion for the outdoors and dogs.