Arcade Expressions: if "string" print "string"?

414
5
Jump to solution
07-22-2020 02:58 PM
EmilyRoutman1
New Contributor

Hi, novice coder here. I am building a web map, trying to use an Arcade expression for my pop-up.

The attribute is "COType" (cluster and outlier type) and the options are 1) "High-High Cluster" 2) "Low-Low Cluster" 3) "High-Low Outlier" 4) "Low-High Outlier" or 5) blank (not statistically significant). 

I want to find an expression where, for each of the COType options, I want it to return a string that describes what the COType means. 

This is what I have: 

if ($feature.COType == "High-High Cluster"):
print("which means this tract and its neighbors have high values.")
if $feature.COType == "Low-Low Cluster":
print("which means this tract and its neighbors have low values.")
if $feature.COType == "High-Low Outlier":
print("which means this tract has high values while its neighbors have low values.")
if $feature.COType == "Low-High Outlier":
print("which means this tract has low values while its neighbors have high values.")
else:
print("is not statistically significant")

When I try to run it, it says "unexpected token" or "unexpected identifier." Is there a print feature for Arcade? If so, what's the syntax? Thank you so much. 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

You don't want to print anything, you just want to return the value for the labeling engine to display.

These situations are best handles by a Decode statement:

Decode($feature.COType,
    "High-High Cluster", "which means this tract and its neighbors have high values.",
    "Low-Low Cluster", "which means this tract and its neighbors have low values.",
    "High-Low Outlier", "which means this tract has high values while its neighbors have low values.",
    "Low-High Outlier", "which means this tract has low values while its neighbors have high values.",
    "is not statistically significant"
)‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

5 Replies
JoshuaBixby
MVP Esteemed Contributor

You don't want to print anything, you just want to return the value for the labeling engine to display.

These situations are best handles by a Decode statement:

Decode($feature.COType,
    "High-High Cluster", "which means this tract and its neighbors have high values.",
    "Low-Low Cluster", "which means this tract and its neighbors have low values.",
    "High-Low Outlier", "which means this tract has high values while its neighbors have low values.",
    "Low-High Outlier", "which means this tract has low values while its neighbors have high values.",
    "is not statistically significant"
)‍‍‍‍‍‍‍‍‍‍‍‍‍‍
EmilyRoutman1
New Contributor

Thank you so much! Maybe there's something wrong on my end, but when I did this it returned "is not statistically significant" for all values. I tried putting a space in front and behind, etc. the text to make sure I was getting the string correct and still nothing. Is there anything else that I could be doing wrong here? 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If the code is returning the default value, then the overall structure is working correctly.  The match needs to be exact, including capitalization.  Also, if this field is linked to domain codes, you might need to compare the actual value and not coded value.

EmilyRoutman1
New Contributor

Just figured out the table had coded values. Used those and it worked! Thank you so much for you help!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I am glad you got it working.  Please go ahead and close out this question then. 

0 Kudos