Display IF yes domain (New to Arcade)

463
5
05-27-2021 06:44 AM
Labels (1)
hherrmann_coj
New Contributor III

Hello!  I have an AGOL hosted feature layer for park amenities.  Each amenity is in it's own field and each park that has any of the amenities, have been set with a domain of YES or NO.  I hope to be able to have the pop up show a simple list of the amenities that exist at each park but not the amenities that are not.  I then hope for people to be able to search for a park based on the amenities that they are interested in having access to.

I was trying to use a tutorial that I found on YouTube but it didn't work for what I am trying to do.  Any feedback and advice would be greatly appreciated.

Below is an example of what my data table looks like if that is helpful.

hherrmann_coj_0-1622123017415.png

 

Tags (1)
0 Kudos
5 Replies
jcarlson
MVP Frequent Contributor

There are a few ways you might tackle this. Considering you want to run a similar check for each attribute, it makes sense to use a loop here. We'll iterate over a feature's attributes, and if the value is "Yes", we'll add it to a string, then return the full string at the end.

 

var out_str = 'Amenities available:'

for (var attr in $feature){
    if ($feature[attr] == 'Yes'){
        out_str += `\n${attr}`
    }
}

return out_str

 

 

Testing this against a sample feature as follows:

jcarlson_0-1622124552142.png

EDIT: I noticed your post referenced a domain. Just be sure that the if condition references the actual value, not the label, so "YES" or 1, or whatever you happen to be using.

- Josh Carlson
Kendall County GIS
hherrmann_coj
New Contributor III

Thank you so much Josh!

So, this is what I have so far, however I seem to be missing something when it comes to returning the name of the field.  Ignorance is sometimes bliss, but sometimes it's not. :D

hherrmann_coj_0-1622128071335.png

 




0 Kudos
jcarlson
MVP Frequent Contributor

Oh, note that the added string is in backticks, not single quotes. ` instead of '. It's next to the 1 key.

In Arcade, as in JavaScript, a backtick string allows you to access variables and other values within a ${...} inside of the string.

EDIT: You could also do out_str += '\n' + attr. We want to add "attr" to the string, as that will reference the key (the attribute name) as opposed to its value.

- Josh Carlson
Kendall County GIS
0 Kudos
hherrmann_coj
New Contributor III

So this isn't working for me.  Not sure what I'm doing wrong.  So I tried to do an IF/ELSE statement but that didn't work either.  I am horrible at stuff like this.  

0 Kudos
jcarlson
MVP Frequent Contributor

Is the layer public? I could pull it into a web map and make a similar attempt using the same data you're working with.

- Josh Carlson
Kendall County GIS
0 Kudos