Select to view content in your preferred language

Attribute Rule Not Saving - Calculation

573
1
10-14-2022 07:59 AM
CaraDavis
New Contributor

Hi all,

I have two layers, one with parcels ("COPY_BaseParcel") and one with buildings ("COPY_BuildingsNew"). Currently there is a field in COPY_BaseParcel named "GPin" which has a unique GPIN ID number for every parcel. 

I have this code to try to see which parcel each building intersects with and add the corresponding "GPin" from the parcel layer to the building layer. 

There must be some kind of error with my code, as ArcGIS Pro will not let me save the attribute rule.

Please help me figure it out!

---

var fsParcel = FeatureSetByName($datastore, "COPY_BaseParcel", ["GPin"])
var fsIntersectParcel = Intersects($feature, fsParcel)
var GPin = First(fsIntersectParcel)
if(fsParcel == null) return null
else return GPin.GPin

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

You are checking fsParcel for null, but you need to check GPin.

The reason for this check: Intersects() returns an empty Featureset when there are no intersecting features. Calling First() on an empty Featureset returns null. Trying to call a field on null will give an error.

So, try this expression:

var fsParcel = FeatureSetByName($datastore, "COPY_BaseParcel", ["GPin"])
var fsIntersectParcel = Intersects($feature, fsParcel)
var GPin = First(fsIntersectParcel)
if(GPin == null) return null
return GPin.GPin

Have a great day!
Johannes
0 Kudos