//Within 10m works but returning 0 for outside of 10m:
// Get the geometry and NamingUnit of the newly added point
var newPoint = Geometry($feature);
var newNamingUnit = $feature.NamingUnit;
// Create a 10-meter buffer around the new point
var buffered = Buffer(newPoint, 10, 'meters');
// Fetch features from the same layer that intersect with this buffer
var allNearbyFeatures = Intersects(FeatureSetByName($map, "Monitoring Devices"), buffered);
// Iterate over nearby features
for (var f in allNearbyFeatures) {
// Check if the feature has the same NamingUnit
if (f.NamingUnit == newNamingUnit) {
var locNum = f.Loc_num;
}
}
// Get the maximum Loc_num value from the nearby features
var maxLocNum = Max(allNearbyFeatures, "Loc_num");
var maxallLocNum = Max(newPoint, "Loc_num")
// Determine the new Loc_num value
if (IsEmpty(maxLocNum)) {
return maxallLocNum + 1;
} else {
return maxLocNum;
}