Just testing in a new environment Pro 3.0 and noticed when applying an attribute rule to a field it there is a validation error ' Unexpected Error. Error on line 18. Unexpected null'. Code below. This rule validates in 2.9 (Image below).
This rule simply updates a field used to rotate cartography points based on the lines direction.
var easementLines = Intersects(FeatureSetByName($datastore, "Easements_Lines", ['objectid'], false), $feature)
var parcelLines = Intersects(FeatureSetByName($datastore, "Parcels_Lines", ['objectid'], false), $feature)
var lotLines = Intersects(FeatureSetByName($datastore, "Lots_Lines", ['objectid'], false), $feature)
var x = null
if (Count(easementLines) > 0){
var x = easementLines
}
else if (Count(parcelLines) > 0){
var x = parcelLines
}
else if (Count(lotLines) > 0){
var x = lotLines
}
if (!(x == null)){
var line = first(x)
var geom = Geometry(line)
var pt0 = geom.paths[0][0]
var brg = Bearing(pt0, Geometry($feature))
if (brg > 90 && brg <= 360) {
return (450 - brg)
}
if (brg >= 0 && brg <= 90) {
return (90 - brg)
}
return null
}
Any thoughts would be great.
Solved! Go to Solution.
In line 17, you try to get the geometry of the line, but in lines 1-3 you explicitly tell Arcade to NOT load the geometries. Does it work if you change that?
In line 17, you try to get the geometry of the line, but in lines 1-3 you explicitly tell Arcade to NOT load the geometries. Does it work if you change that?
Clearly, it's late and I'm bad at life 🤣. How embarrassing, I should know better.
Edit: And @JohannesLindner spotted it before I did, to consume the geometry of a feature that has been queried, the featureset should be created with return geometry set to true.
It is a good practice to always check for null when you call `first`, First can return null if the featureset is empty, which can cause subsequent code to fail. And just to be safe, because the error is pointing in line 18 the geometry of the line might be null here so add a check for that too.
var line = first(x)
//check if line is null
if (line == null) return; //do nothing
var geom = Geometry(line)
if (is_empty(geom )) return; //check if the geometry is null
Now to explain "well it worked in 2.9 why does it fail in 3.0". To validate an Arcade script , AR picks a row in the table and makes that row $feature to do the validation against. It could be the case the 2.9 gives a different row than 3.0 and resulting in a failure in your script.
Thank you for all this info! Still learning.