ArcGIS Pro 2.7.1, and SDE
1) how to generate or populating in a new # in a field that is already created in exist sde feature class for example 100,101,102 each row? Right now it is 0.
2) How do I generate or populating a new # in order in a field every time a new row is create in exist feature class? again, example, 101,102,103
Please kindly advise. Thank you
Alex
Solved! Go to Solution.
Select your field
just choose sequential number then add what you want and it fills in the code block
Please check How To: Create sequential numbers in a field using Python in the Field Calculator
Select your field
just choose sequential number then add what you want and it fills in the code block
Thank you. I noticed that not only 0 in PID. there are some # already in PID. how can avoid duplicate sequential # and existing # in PID field if it happens? I am not able to change what # is already created except "0" due to production. That screenshot you provide , it looks like trigger already after it calculated a field set up then every time it creates a new row? or do i need to do that every time manual set up calculate a field?
You have to know where to begin. The example I gave just added to what was there.
If you want to edit the start number, then you have to change the start value in the code block.
If you want to continue on from a start location, then the quickest is to highlight the rows that you want to calculate the values for, then continue on.
field calculations on work on selected rows.
If you are looking for "automagic" that is a much uglier path and isn't a simple field calculation thing.
If you only have 10 or so to do at a time... manual is quickest.
Understood. Thank you for the information @DanPatterson @JayantaPoddar . very helpful.
@DanPatterson I just had a requested that need to add text in a field for example "CITY-100"
I tried to rerun but it doesn't work. Also, I found out that this type field has long and numeric. Please advise.
Please ensure you are working on a Text field.
The only change I have made is in the last line of the code block.
In Code Block
rec=0
def autoIncrement():
global rec
pStart = 1
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec += pInterval
return "City-" + str(rec+100)
Expression
autoIncrement()
You will have to make adjustments in the code block as Jayanta has shown.
The "sequential number" shortcut writes the basic code for it, which you can alter.
Also note, that if you have to do this often, you can save the field calculator expression and just reload it next time you need it
Great. Thank you! @DanPatterson @JayantaPoddar