thomas.uk

Populate a field as sequential number using autoIncrement in field calculator

Discussion created by thomas.uk on Apr 9, 2014
Latest reply on Sep 4, 2015 by rfairhur24
Hi all,
I need to populate a field with sequencial numbers.
I could go the easy way and input in the field calculator: FIELD = 1+ [FID]

But I want my data to be first sorted so what i would like would be more something like
1) Sorting my data
2) FIELD = ROW
And so once sorted the FID is not relevant to the row number...


I've read things online and it seems that autoIncrement is my solution but I can't seems to have it working.
Here is the code I got from the help:

Expression:
autoIncrement()

Expression Type:
PYTHON_9.3

Code Block:
rec=0
def autoIncrement():
global rec
pStart = 1 #adjust start value, if req'd
pInterval = 1 #adjust interval value, if req'd
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec

Here how I input it:


Here's my error message:


My field i'm trying to populate is called label and is a short integer.

Any ideas?

Outcomes