Select to view content in your preferred language

Pop-up Arcade Expression- Show List of Field Names if field Value matches expression

5434
17
Jump to solution
01-17-2020 08:57 AM
DaveAlmond
New Contributor III

Xander Bakker

I would like to create a popup that shows field names in the attribute table if the field value for the feature equals 1. 

Specifically, my Bus Stops table has a field for each bus route (A, B, C, D, etc. 22 in all) if the stop is served by a route, the field value is 1, if not, the field value is 0. I want the popup to show only the routes that serve the selected stop.  I know I need to iterate the route fields (but not all fields in the table) to evaluate whether the route field value is 1, and then add those field names (the route name) to a list and then return the list. I could do this in Python, but I am not as familiar with Arcade.  I tried checking some of the other posts on lists https://community.esri.com/people/mmckeanesriaustralia-com-au-esridist/blog/2019/10/07/creating-aggr...  but I couldn't glean what I needed since my Arcade is very basic. Thanks!

17 Replies
XanderBakker
Esri Esteemed Contributor

Hi Ben Baker ,

Great question. I am not sure, but from your observation I would say that it does not. An Arcade expression in this case lives in the web map when you define it for the pop-up, symbology or labels. A hosted layer view is created of the data and will not have any knowledge of the existence of any Arcade expressions in the web map using the original layer. 

Maybe you can elaborate a bit more about your use case, to see if there is a solution.

0 Kudos
BenBaker1
Occasional Contributor

I created them under the Visualization tab of the Item Details, hoping that they would participate in any analysis processes applied to that layer, but that was not the case in my experience. Perhaps that could be an improvement in future AGOL releases.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Ben Baker ,

You can always create an https://community.esri.com/community/arcgis-ideas . Every release many ideas posted by users are implemented in ArcGIS.

0 Kudos
AngeliaH
New Contributor II

Hey XanderBakker!  I am trying to use your expression to go through fields and if the value is yes then it list the activity field name.  However my expression returns empty. I am new to looping in Arcade expressions. Can you take a look if you have a moment? The idea is to look through 30+ fields for a yes value and then list the field in the pop-up. This is using the ParkLocator ESRI solution.

var activity_fields = FeatureSetbyName($map,'ParkRecreationFacilities', ['Adult_Center', 'Restrooms', 'Bike_Trail']);

var activities_available = "Activities at this park: ";

for (var i in activity_fields) {
if ($feature[activity_fields[i]]=="Yes"){
activities_available += TextFormatting.NewLine + " - " + activity_fields[i];
}
}

return activities_available

0 Kudos
JessieMandirola
New Contributor

This bit of code was exactly what I needed to fix a problem I was having so thank you! However, is it possible to return the field alias instead of the field name? My field names are truncated and not very useful. The aliases would be more informative for the user but I cannot figure out how to call those instead.

0 Kudos
OPSGIS
by
New Contributor

Hi @XanderBakker , this has been very helpful. Do you have any idea if we can pull multiple field names in a different field based on certain yes/no attributes. For example, if I have fields A,B,C,D and I create a new field called 'Final' where I want to list the fields that have the attributes 'yes' in it. 

Can you help me with that?

0 Kudos
by Anonymous User
Not applicable

Thanks for all the examples on how to do this. Tried a similar approach but building an array for each feature then concatenating to make a comma-separated string. Here's my expression:

var programs = ['SilvaCarbon', 'SWAMP', 'Climate_Fellows', 'SHuFFLE'];
var countryPrograms = [];

for(var p in programs) {
    if ($feature[programs[p]] == 1) {
        Push(countryPrograms, programs[p]);
    }
}

return Replace(Concatenate(countryPrograms, ', '), '_', ' ');

It works in Map Viewer, but only if a field list follows it:

IanYauUSFS_0-1646783462260.png

I don't want a field list, but when I remove it, the expression no longer works, it just doesn't show up:

IanYauUSFS_1-1646783502609.png

 @NW_-_MikeCibicki__GISS_ suggested I try it in Map Viewer Classic and it works there. Seems like a bug?

0 Kudos
by Anonymous User
Not applicable

Found the issue. Although the third field name is 'Climate_Fellows', it appears in the Globals list as $feature["Climate_Fellows"] while all the other fields appear as $feature.FieldName. I don't understand why that is. Is it indicating that field has an alias?

Rewrote the expression to just use four if statements instead of looping through the list of field names and it works. Would love any clarification on that one field's formatting and how I could correctly use it in a for loop.

0 Kudos