I am trying to create an attribute rule for a point feature class (Manholes) in which I want a field (FacilityID) to populate based on the combination of intersection with a polygon grid (Quarter Section) and a Database Sequence. For example, if I create a new point feature in grid 564 and the point is the 55th point in grid 564, I want the attribute rule to populate the FacilityID field with 564-55. I also want this rule to work with any grid, each which has its own Database Sequence counting the number of points. Here is what I have so far:
This script fails with the following error:
However, the script works if I hardcode the Database Sequence string name into line 12:
Does anyone know what might be causing the inputSequenceName to fail when passed into the NextSequenceValue instead of the hard coded string?
I'd appreciate any help you can provide since this is my first time diving into Attribute Rules with Arcade. Thanks!
Solved! Go to Solution.
It's hard to copy code from screen grabs. In the future, please use the "Insert Code Sample" button in the comment window: Expand the toolbar, then click this button and chose Javascript as language.
// The error is in this line
var inputSequenceName = 'ManholeSequence' + Text(matchedZone)
// matchedZone is a feature set, not a field!
// Try this:
var inputSequenceName = 'ManholeSequence' + Text(matchedZone.GRID)
It's hard to copy code from screen grabs. In the future, please use the "Insert Code Sample" button in the comment window: Expand the toolbar, then click this button and chose Javascript as language.
// The error is in this line
var inputSequenceName = 'ManholeSequence' + Text(matchedZone)
// matchedZone is a feature set, not a field!
// Try this:
var inputSequenceName = 'ManholeSequence' + Text(matchedZone.GRID)
Johannes,
Thank you so much for the reply! I appreciate you showing me how to insert the code sample. Thanks for clarifying matchedZone is a feature set. Using your revision, I got my attribute rule to work the way I want. The only thing I had to change was removing the inputSequenceName variable and directly including the 'ManholeSequence' + Text(matchedZone.GRID) in the NextSequenceValue function. When I passed in the variable, it threw a null return error. Anyways, it's working now, so thanks again for the help!
// Create reference to the Quarter Section layer in the map
var zones = FeatureSetByName($datastore,"QuarterSection",["GRID"],true)
// Get a feature set of zones that intersect the point
var intersectingZones = Intersects(zones, Geometry($feature))
// Select the first record in the feature set
var matchedZone = First(intersectingZones)
// Return the grid value of the selected zone with the sequence number
return IIf(IsEmpty(matchedZone), null, matchedZone.GRID + "-" + NextSequenceValue("ManholeSequence"+Text(matchedZone.GRID)))