Select to view content in your preferred language

Using Attribute Rules to Create Sequential ID

1823
2
Jump to solution
08-18-2023 08:25 AM
Labels (1)
ShaiBravo
Occasional Contributor

Hi there, I was looking through the forum and couldn't find an exact solution to my problem.

I am using ArcGIS Pro and want to create a new sequential number every time a new point feature is created within my layer. I first want to sort OBJECTID by descending, which would give me the last CW_ID I used. I then want the new feature to have a CW_ID one higher than the last one used. How would I do this using arcade and attribute rules?

For example, if the last CW_ID after the OBJECTID sort was SAN6249, I want the new feature created to have a CW_ID of SAN6250 automatically. As a side note, each new CW_ID with start with SAN, so I am assuming there will have to be a split to isolate the integer and then a concatenation somewhere to recreate the string.

Please let me know if you need any more details.

Thanks!

1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

The really easy way:

Create a database sequence

// Calculation Attribute Rule
// trigger: Insert
// field:CW_ID

var seq = NextSequenceValue("SequenceName")
return "SAN" + seq

 

 

If for some reason you can't create sequences, you'll have to do it the harder way:

// Calculation Attribute Rule
// trigger: Insert
// field:CW_ID

// get the latest feature with a CW_ID
var last_feature = First(OrderBy(Filter($featureset, "CW_ID IS NOT NULL"), "OBJECTID DESC"))
// get the last CW_ID and add 1
var seq = IIf(last_feature == null, 0, last_feature.CW_ID) + 1

return "SAN" + seq 

Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

The really easy way:

Create a database sequence

// Calculation Attribute Rule
// trigger: Insert
// field:CW_ID

var seq = NextSequenceValue("SequenceName")
return "SAN" + seq

 

 

If for some reason you can't create sequences, you'll have to do it the harder way:

// Calculation Attribute Rule
// trigger: Insert
// field:CW_ID

// get the latest feature with a CW_ID
var last_feature = First(OrderBy(Filter($featureset, "CW_ID IS NOT NULL"), "OBJECTID DESC"))
// get the last CW_ID and add 1
var seq = IIf(last_feature == null, 0, last_feature.CW_ID) + 1

return "SAN" + seq 

Have a great day!
Johannes
ShaiBravo
Occasional Contributor

Thanks so much!

0 Kudos