How to generate or populating a field

1317
9
Jump to solution
03-16-2021 02:26 PM
AlexP_
by
Occasional Contributor III

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.

AlexP__0-1615929818962.png

 

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

 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

sequential_calc1.png

 

Select your field

just choose sequential number then add what you want and it fills in the code block


... sort of retired...

View solution in original post

9 Replies
JayantaPoddar
MVP Esteemed Contributor
DanPatterson
MVP Esteemed Contributor

sequential_calc1.png

 

Select your field

just choose sequential number then add what you want and it fills in the code block


... sort of retired...
AlexP_
by
Occasional Contributor III

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?

0 Kudos
DanPatterson
MVP Esteemed Contributor

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.


... sort of retired...
AlexP_
by
Occasional Contributor III

Understood. Thank you for the information @DanPatterson @JayantaPoddar .  very helpful.

0 Kudos
AlexP_
by
Occasional Contributor III

@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.

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

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()

 

 

 

 

 



Think Location
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
AlexP_
by
Occasional Contributor III

Great. Thank you! @DanPatterson @JayantaPoddar 

0 Kudos