Select to view content in your preferred language

Arcade syntax different for shapefile vs feature service?

337
4
05-15-2023 11:09 AM
Labels (1)
wayfaringrob
Frequent Contributor II

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.

rburke_0-1684173779849.png

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.

rburke_1-1684174176659.png

Taking suggestions on how to work around this. Thanks!

0 Kudos
4 Replies
JohannesLindner
MVP Frequent Contributor

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:

  • don't split by ", ", just use the comma without space
  • check the length of the split. if it's 1, return a default value (eg the whole string, or an error message)

 

var f = Replace($feature.TextField2, " ", "")
var f_split = Split(f, ",")
if(Count(f_split) > 1) { return f_split[1] }
return f

Have a great day!
Johannes
0 Kudos
DavidPike
MVP Frequent Contributor

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?

0 Kudos
JohannesLindner
MVP Frequent Contributor

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...


Have a great day!
Johannes
0 Kudos
RhettZufelt
MVP Notable Contributor

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:

RhettZufelt_0-1684179068009.png

 

R_

0 Kudos