I've run into an issue here where the same exact expression will be validated and work fine for the shapefile version of a layer, but not the web version. The only difference is the field name (truncated in the shapefile). It's a text field.
Shapefile on right, feature service on left.
It throws an error that the index is out of bounds. Is it just looking at a random feature, seeing a null value, and assuming none of the features have values? For features with no county signed route, in the shapefile, they are just populated with a space. A typical field with a value reads something like 'STATE OF IOWA, Z 16, N' and the Arcade spits out Z16 as its label.
Taking suggestions on how to work around this. Thanks!
Hmm, I couldn't reproduce that behavior, the syntax does not differ.
A possible explanation could be that your service contains values for which the expression fails, eg null values or strings without commas, strings where there is no space after the comma.
Workarounds:
var f = Replace($feature.TextField2, " ", "")
var f_split = Split(f, ",")
if(Count(f_split) > 1) { return f_split[1] }
return f
Yes I think there's some more robust validation happening for the Feature Service input. I'd go with Johannes's solution. @Johannes there's still no Try - Except equivalent in Arcade is there?
Nope still waiting on that one. Related idea: https://community.esri.com/t5/arcgis-pro-ideas/add-error-handling-try-catch-to-arcade-language/idi-p...
I am able to reproduce that error IF there is a value in the label field that is null or does not contain a comma.....
Along with @JohannesLindner stated, you can also put some console() statements in there to see what is actually being returned from the representative row:
R_