Hide Field in Pop-up Using Arcade

9309
17
02-23-2021 03:42 AM

Hide Field in Pop-up Using Arcade

This document will walk you through how to hide a field in a pop-up using Arcade.  You can use this to hide a field that contains a particular value, or if the field is blank/NULL.

1.  Create an Attribute Expression for the field you wish to hide by clicking the 3-dot button next to the layer within the Web Map > Configure Pop-up

JakeSkinner_0-1614078939695.png

2.  Scroll down to Attribute Expressions and click Add:

JakeSkinner_1-1614078992673.png

 

3.  Specify an IIF statement for the field you wish to hide.  For the trueValue, specify None.  For the falseValue, specify inline.  Here is an example:

IIF($feature["Meter_Meter_Flow"] == -999 || IsEmpty($feature["Meter_Meter_Flow"]), "None", "inline")

The above Arcade expression will hide the field Meter_Meter_Flow if the value is -999, or if the value is blank.

4.  Under Pop-up Contents change the Display to A custom attribute display

JakeSkinner_2-1614079359064.png

 

5.  Click CONFIGURE

6.  In the Custom Attribute Display dialog, add any fields you wish to show in the pop-up

JakeSkinner_3-1614079493439.png

7.  To hide a field, you will need to switch to View HTML Source.  This will allow you to enter HTML code.

JakeSkinner_4-1614079563194.png

8.  Specify the following HTML to hide the field:

<span style="display:{expression/expr0}">
<b>Meter Flow:</b>  {Meter_Meter_Flow}<br />
</span>

The expression/expr0 above is the id of the Attribute Expression previously configured:

JakeSkinner_5-1614079987617.png

 

{Meter_Meter_Flow} on the second line represents the name of the field.  This value will display if the IIF statement returns False.  Here is how the Custom Attribute Display appears:

JakeSkinner_6-1614080132996.png

9.  Click OK to close the Custom Attribute Display and OK again to close the Configure Pop-up panel

If the Meter_Meter_Flow field is not blank, and is not -999 it will display:

JakeSkinner_7-1614080343312.png

If it is, it will be hidden:

JakeSkinner_8-1614080383127.png

 

 

Comments

Hi @JakeSkinner -

This is great. Is there any way to do this en-masse for many fields within one expression? Right now I am getting ready to write this expression & HTML code ~90 times for all of the fields I need to deal with. 

Thank you!

Hi @erica_poisson ,

Yes, you can when you use the new Map Viewer. In this case, you will not add an expression (virtual field) to the pop-up, but you will add an Arcade Element and configure something like:

Function HasDomain(f, fldname) {
    return Domain(f, fldname) != Null; 
}

Function GetAlias(f, fldname) {
    var esquema = Schema(f);
    var flds = esquema["fields"];
    for (var i in flds) {
        var fldinfo = flds[i];
        if (fldinfo["name"]==fldname) {
            return fldinfo["alias"];
        }
    }
    return fldname;
}

Function GetFieldNames(f, excludeflds) {
    var fldlst = [];
    var esquema = Schema(f);
    var flds = esquema["fields"];
    for (var i in flds) {
        var fldinfo = flds[i];
        // Console(fldinfo["name"]);
        // Console(Includes(excludeflds, fldinfo["name"]));
        if (!Includes(excludeflds, fldinfo["name"])) {
            Push(fldlst, fldinfo["name"]);
        }
    }
    Console(fldlst)
    return fldlst;
}

var fs = FeatureSetByName($datastore, "_8_de_formulario");
var oid = $feature.objectid;
var sql = "OBJECTID = @oid";
var f = First(Filter(fs, sql));
var excludeflds = ['globalid', 'objectid', 'prueba', "x_coord","y_coord","EditDate","Editor"];
var flds = GetFieldNames(f, excludeflds); 
var info = [];
var atts = {};

for (var i in flds) {
    var fldname = flds[i];
    if (!IsEmpty(f[fldname])) {
        var alias = GetAlias(f, fldname);
        Push (info, {'fieldName': alias})
        if (HasDomain(f, fldname)) {
            atts[alias] = DomainName(f, fldname);
        } else {
            atts[alias] = f[fldname];
        }
    }
}

return {
    type: 'fields',
    title: 'Detalles de la actividad', 
    description : '(con Arcade)',
    fieldInfos:  info,
    attributes : atts 
}

 

In this case, I have a feature service that stores the results of a Survey with a lot of conditional questions. In order to avoid the empty (non-relevant) fields being showed in the pop-up, you can use this to only show those that have information. 

On line 33 you define the layer that you want to connect to and on line 37 I define a list of fields that I don't want to show. 

This is super useful, however, is there a way to have the line break not show up if your 'hidden' value isn't at the bottom of the popup list? 

This is what it looks like if I have values for all the fields

VanessaSimps_0-1655327650974.png

Here is when I don't have a Valve ALTID value:

VanessaSimps_1-1655327720252.png

I am not loving the big gap that is created here. I could move the values to the bottom of my list, but the end user wanted the list in this order. 

Thanks!

Vanessa

Hi @VanessaSimps ,

The comment above your comment explains just how to do that using the new Map Viewer and Arcade elements.

 

Let me know if you have any questions on how to do this.

Hi @XanderBakker I have a question related to this topic: How could I display a list of different fields in the pop-up based on the values in a certain field? For example, I would like to configure a pop-up for hundreds of business locations. Due to data sharing agreement with the business owners, some of the fields can be shown on the pop-up for some business, but cannot for others. I have a field (e.g., privacy_level with values from 0 to 5) to indicate that. So I want to display, say field_A, field_B, field_C, field_D for locations with privacy level larger than 2, while only field_A and field_B for locations with privacy level smaller than or equal to 2. How could I use Arcade to accomplish that? 

Thank you! 

@Vanilla2020 

you could use something like this article talks about. I realize this article is for relative time, but you can use the idea to create your if then statement.

https://community.esri.com/t5/commercial-blog/arcade-calculating-relative-time-for-popups-and/ba-p/8...

Hi @Vanilla2020 ,

 

Have a look at the "GetFieldNamesOnPrivacy" function below: 

Function HasDomain(f, fldname) {
    return Domain(f, fldname) != Null; 
}

Function GetAlias(f, fldname) {
    var esquema = Schema(f);
    var flds = esquema["fields"];
    for (var i in flds) {
        var fldinfo = flds[i];
        if (fldinfo["name"]==fldname) {
            return fldinfo["alias"];
        }
    }
    return fldname;
}

Function GetFieldNamesOnPrivacy(f) {
    // privacy_level with values from 0 to 5) 
    // I want to display, say field_A, field_B, field_C, field_D 
    // for locations with privacy level larger than 2, 
    // while only field_A and field_B 
    var fldlst = [];
    var level = f["privacy_level"];
    if (level > 2) {
       fldlst = ["field_A", "field_B"];
    } else {
        fldlst = ["field_A", "field_B", "field_C", "field_D"];
    }
    return fldlst;
}

var fs = FeatureSetByName($datastore, "_8_de_formulario");
var oid = $feature.objectid;
var sql = "OBJECTID = @oid";
var f = First(Filter(fs, sql));
// var excludeflds = ['globalid', 'objectid', 'prueba', "x_coord","y_coord","EditDate","Editor"];
var flds = GetFieldNamesOnPrivacy(f); 
var info = [];
var atts = {};

for (var i in flds) {
    var fldname = flds[i];
    if (!IsEmpty(f[fldname])) {
        var alias = GetAlias(f, fldname);
        Push (info, {'fieldName': alias})
        if (HasDomain(f, fldname)) {
            atts[alias] = DomainName(f, fldname);
        } else {
            atts[alias] = f[fldname];
        }
    }
}

return {
    type: 'fields',
    title: 'Detalles de la actividad', 
    description : '(con Arcade)',
    fieldInfos:  info,
    attributes : atts 
}

 

Thank you very much for all your reply. I will try this out! 

Hello, I have tried using the expression: 

IIF(isEmpty($feature.Organizati, "None", "inline"), as an attribute expression in my popup configuration but it is not working.

I am using Map Viewer and I want to hide those fields that have no data when the popup is displayed. 

Do I need to add an attribute expression? or an Arcade expression as content? What is the difference between these? 

Thank you

@AdrianaCalderon you then have to go into the pop-up's html and configure the html so it knows what to show/not to show in the pop-up. I think one of the link

I think this might have the info https://community.esri.com/t5/arcgis-online-blog/conditional-field-display-with-arcade-in-pop-ups/ba...

 

or this thread https://community.esri.com/t5/arcgis-online-questions/can-i-eliminate-empty-values-using-arcade-in-m...

Is there a way to configure this type of schema in the new Map Viewer? I don't see an option for custom HTML pop-ups in there but the arcade abilities seem more robust. Is this functionality now baked in?

@NatalieRobbins in the new Map Viewer, select Add Content in the Pop-up pane, and then select Text:

JakeSkinner_1-1674502611811.png

You can then format your text with supported HTML using the Source icon:

JakeSkinner_2-1674502687634.png

 

 

@NatalieRobbins Are you using Portal or AGO?

I noticed that when in Portal, the "source" html button is missing, but if you are in AGO it is there as @JakeSkinner has shown in their post. 

Curios to hear from Esri if there is some other way to handle HTML in pop-ups or if this was simply not added yet to the pop-up configuration in Portal.

 

There is discussion of this here

-Vanesa

This is very helpful. Thank you @Vanilla2020 . I'm getting the error when trying to access your featureset or mine:

Execution Error: Failed to open Layer: Feature layer must be created with either a url or a source

Any thoughts on why this is happening?

@XanderBakker 

Using the expression above. How would you go about applying logic to also hide fields with a 0 (zero) value?

@JustinConnerWR I would imagine if you replaced the -999 with zero in the this:

IIF($feature["Meter_Meter_Flow"] == -999 || IsEmpty($feature["Meter_Meter_Flow"]), "None", "inline")

so it would look like this:

IIF($feature["Meter_Meter_Flow"] == 0 || IsEmpty($feature["Meter_Meter_Flow"]), "None", "inline")

 

Haven't tested it, but would give it a try and see if that works.

I saw this return in arcade expression

return {
    type: 'fields',
    title: 'Detalles de la actividad', 
    description : '(con Arcade)',
    fieldInfos:  info,
    attributes : atts 
}

If that Arcade expression is {expression/expr0}, I was wondering, how do you grab either fieldInfos OR attributes value in the html code? for example

<p> my Field Info: {expression/expr0} </p>
<p> my Attribute: {expression/expr0} </p>

This will result as [object Object]

Please advice. Thank you.

 

 

Version history
Last update:
‎02-23-2021 03:42 AM
Updated by: