Select to view content in your preferred language

Automatic numbering of object

496
4
Jump to solution
06-16-2023 10:03 AM
MaikHeinze
New Contributor II

Hello everyone,

is it possible to create a rule using Arcade that assigns an individual number starting from 1 to an object?

When placing an object, it should receive the number 1. When placing a second object, the second object should receive the number 2. And so on...

Now, if I have 10 objects numbered from 1 to 10, and let's say I delete object number 5, all the objects following 5 should be renumbered from 6 to 9.

Is this possible?

0 Kudos
1 Solution

Accepted Solutions
MobiusSnake
MVP Regular Contributor

It might be possible but I think it could be horribly inefficient.  Imagine you've got 10,000 records and you delete record number 5, since attribute rules are executed against one record at a time you'd need to wait for 9,995 updates to take place.

What do you need a sequence like this for?  Assuming you aren't working with versioned data, you could derive it from the Object ID at the time it's required.  If you are working with versioned data, you could use editor tracking and the create date to perform this type of operation at the time it's required.

View solution in original post

0 Kudos
4 Replies
MobiusSnake
MVP Regular Contributor

It might be possible but I think it could be horribly inefficient.  Imagine you've got 10,000 records and you delete record number 5, since attribute rules are executed against one record at a time you'd need to wait for 9,995 updates to take place.

What do you need a sequence like this for?  Assuming you aren't working with versioned data, you could derive it from the Object ID at the time it's required.  If you are working with versioned data, you could use editor tracking and the create date to perform this type of operation at the time it's required.

0 Kudos
MaikHeinze
New Contributor II

I am working with a predefined range of numbers that need to be assigned to cabinets. The maximum number of assigned numbers will never exceed 20. This should still be within the limits, right?

Is it possible to create a rule for this in Arcade? And how would it look like?

0 Kudos
MobiusSnake
MVP Regular Contributor

I think it would be reasonable with a maximum 20 records.  I don't write these types of Arcade statements very often so I'd defer to others (I did put a rough idea below however), but are you working in an Enterprise environment with versioning?  If so I don't think it would be possible without the risk of ID collisions upon reconciliation.

If you aren't working with versioning, I think something like these two rules would work:

  • Rule one, on create:
    • Query the feature set and find the maximum existing ID
    • Set the new record's ID to the maximum plus one
  • Rule two, on delete:
    • On the delete operation, get the deleted feature's ID
    • Get a feature set with all features that have a higher ID than that number
    • Decrement each ID by one, updating each feature

Alternatively, as part of your editing workflow, create a simple Python script (maybe deployed as a GP tool) that reads the features in an update cursor, ordering by OID or creation date, and sets the IDs in a sequence.  You could also do this with the Field Calculator and the "Code Block" parameter.  Again, if versioning is involved, it gets more complicated (but still possible this way).

Also, just to be 100% sure, what is your data source?  A File GDB?  Or - since this question is under the ArcGIS Online community - are you using an ArcGIS Online hosted feature layer?  If it's an AGOL feature layer I'm fairly certain they don't support attribute rules yet.

0 Kudos
DavidForbuss1
Occasional Contributor III
0 Kudos