Hi All, I'm relatively new to Arcade but can't figure out this When function. I have a Right expression that returns the last three characters of a field $feature.info_headline when applied as a separate arcade expression. However when I apply the same expression as a variable in front of a When expression I get no errors when tested but also no results are returned? Can someone point me where I am going wrong with this expression? Is there a rule about variables I am missing?
var right3 = Right($feature.info_headline, 3);
var warning_level = When(right3=='Red', 'Red', right3=='nge', 'Orange', 'Watch');
I'm trying to get the expression to populate a new Color Style such that if the last three characters in the field $feature.info_headline are 'Red' the value returned is 'Red', or if he last three characters are 'nge' the value returned is 'Orange', else return 'Watch'.
I know there might be some options using nested IIf functions but thought the When function would be simple enough to do what I am trying.
Cheers
Derek
Hi Derek Phyn ,
That is correct you should always return the result of the expression.
For readability especially when you have a lot of values to check you could spread the "when parts" over multiple lines like this:
I also often use if - else if - else statements:
You can also use a dictionary with the options: