In ArcPro, is it possible to automatically add or edit an attribute in an existing field when a new polygon is created?
Example: A polygon is split in 2. One of the two polygons will have the field "Number" updated.
Original polygon was "Number" '1'
New polygon from the split will then become "Number" '2'
This would only work if it added a number which is +1 of the highest number in that field of all polygons.
Example: "Number" '1234' is the highest number in the "Number" field.
Original polygon being split is "Number" '1'
New polygon from the split will have "Number" '1235'
I can't find any information about whether or not this is even possible.
Thanks for your time!
Look into attribute rules.
That's a great resource, thanks!
I got as far as trying to create a calculation attribute rule, using Arcade to build an expression.
I must be way off. It shows an error in the attribute rules table (red icon next to the rule). The expression is valid, but it's not working.
*****
// Define the field name
var field_name = "POLY_NUM";
// Get the maximum value in the field
var max_value = Max(FeatureSetByName($datastore, "R11_GE", [field_name]), field_name);
// Add 1 to the maximum value
if (IsEmpty(max_value)) {
return null; // or return 1 if you want to set 1 as the minimum
} else {
return max_value + 1;
}
******
I had the trigger set to insert. I guess update might work too, but maybe that updates the number if you're just changing a boundary, which wouldn't work out well.
Seems like this is much more complex than I had imagined. I really appreciate you pointing me in the right direction. It was useful to read about, even if it didn't work out.
If anyone stumbles on this and is looking for something that might work, here is what worked for me.
Here you can create a calculation rule using the Arcade language
// Define the field name
var field_name = "POLY_NUM";
// Get the maximum value in the field
var max_value = Max(FeatureSetByName($datastore, "R11_GE", [field_name]), field_name);
// Add 1 to the maximum value
return max_value + 1;
*****end*****
POLY_NUM is my polygon number field.
R11_GE is my polygon shape file
An improvement to this code would be to find any "unused" numbers before the MAX number. Ie: numbers 7-9 out of 1-99 are not populated. Finding a way to select for number 7, because it is not yet used, may be better than using number 100, which would be the MAX+1
That is out of my grasp and I'll have to settle for the MAX number. Perhaps this helps someone with a similar problem.
Hi @GregEscott - if it helps, here is some additional info about using a database sequence with attribute rules. https://community.esri.com/t5/attribute-rules-videos/generating-unique-ids-with-attribute-rules/td-p...