I'm creating a workflow with a several access points (Pro, Web App, Field Maps) and am trying to use attribute rules (where possible) and field calculations (where attribute rules don't work) to calculate a unique record ID. One thing to note is that the Pro or Web App interface accesses one DB while the Field Maps interface accesses a different DB with a replica synchronizing between the two. The record ID looks at the intersection of several datasets to calculate the ID as a point feature is created. The arcade will will return the features from two polygon datasets that intersect the point feature being created. Then it will use one of the polygon features to determine how many other point features are contained within to get a count. Then the ID is created using attribute values from the two polygon datasets and the count (increased by one).
The problem I'm running into is that the code seems to behave differently in attribute rules vs field calculation. In field maps, everything works as expected using field calculations. When I add a point to within any polygon, the ID increments correctly regardless of whether any points already exist within the polygon. When working in Pro or a Web App (attribute rules), if I try to add a new point where other points already exist within the polygon, everything works fine the the ID is incremented correctly. However, if there are no existing points within the polygon, the initial ID increments one too many (the numbering starts at 2 instead of 1), but subsequent IDs follow the lead of the first and increment correctly from there(3...4...5...and so on). This last part is weird because the arcade never looks at any of the IDs within the polygon, it only looks at the number of points.
I use the same code for the attribute rules and the field calculations, only changing how the feature set is referenced.
In the attribute rules I reference the feature sets by $datastore and use the DB name for the dataset:
var Poly1 = First(Intersects($feature, FeatureSetByName($datastore,'DataOwner.poly1_DB_Name')))
var poly2 = First(Intersects($feature, FeatureSetByName($datastore,'DataOwner.poly2_DB_Name')))
if (poly1==null) return "no poly1 found"
if (poly2==null) return "no poly2 found"
var PointCount = SUM(Count(Intersects(poly2,FeatureSetByName($datastore, 'DataOwner.point_DB_Name'))),1)
var PointCountFormat = Text(PointCount,'00')
var PointID = poly1['Att1']+poly1['Att2']+poly2['Att1']+PointCountFormat
return PointID
And in the Field Maps field calculation I reference the feature set by $map and use the map name of the dataset :
var poly1 = First(Intersects($feature, FeatureSetByName($map,'poly1_Map_Name')))
var poly2 = First(Intersects($feature, FeatureSetByName($map,'poly2_Map_Name')))
if (poly1==null) return "no poly1 found"
if (poly2 ==null) return "no poly2 found"
var PointCount = SUM(Count(Intersects(poly2 ,FeatureSetByName($map, 'point_Map_Name'))),1)
var PointCountFormat = Text(PointCount,'00')
var PointID = poly1['Att1']+poly1['Att2']+poly2 ['att1']+PointCountFormat
return PointID
Could this be a problem of timing differences between when DB attribute rules fire off vs Field Maps field calculations?