Rule in ArcGIS Pro 3.0 wont validate, 2.6-2.9 zero issues. Does 3.0 have a new compiler?

564
4
Jump to solution
10-18-2022 11:29 AM
Jake_S
by
Occasional Contributor II

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
}

 

 

JS_Esri_1-1666117649370.png

 

JS_Esri_0-1666117598656.png

 

Any thoughts would be great.

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

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?


Have a great day!
Johannes

View solution in original post

4 Replies
JohannesLindner
MVP Frequent Contributor

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?


Have a great day!
Johannes
Jake_S
by
Occasional Contributor II

Clearly, it's late and I'm bad at life 🤣. How embarrassing, I should know better.

0 Kudos
HusseinNasser2
Esri Contributor

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.

 

 

 

 

Jake_S
by
Occasional Contributor II

Thank you for all this info! Still learning.

0 Kudos