Select to view content in your preferred language

Arcade auto populating data field based on intersecting other layer

846
1
07-27-2022 07:57 AM
Labels (1)
KWilliams
Occasional Contributor

Hello - I am looking for a way to auto populate a Project name on a line feature based on if the field operations crew draws that line within a certain polygon.

The polygon serves as a boundary and has the field "Project" and is populated with the area's Project name. When the field crew adds a new polyline, I want the polyline's "Project" field to auto populate with the polygon's pre-populated "Project" 

I am new to Arcade, kind of thrown into learning all of this on the spot on active projects. I'm pretty lost.

I've tried this code verbatim and I'm not understanding the error message of 'cannot call member method on null'

KWilliams_0-1658933711347.png

 

0 Kudos
1 Reply
JohannesLindner
MVP Alum

When validating your expression, Arcade will return empty FeatureSets with functions like Intersects().

Calling First() on an empty FeatureSet returns null.

So xs_feat is null, thus you can't call a member method on null.

You have to check for null before you continue:

 

var other_layer = ...
var xs_feat = First(Intersects($feature, other_layer))
if(xs_feat == null) { return "Some default value" }
return xs_feat.Project

 

 


Have a great day!
Johannes