how to create a correlative, based on a start number (script field calculator)

167
4
Jump to solution
05-18-2020 03:55 PM
RTMRTM
by
New Contributor II
I try to create a script, which generates a correlative number (ID)
the start number can vary,
will not start from 1 or 0
it can be any number start  and the number of rows can also change
done this example but it didn't work
rec=0
def autoIncrement():
    global rec
    pStart = 11 #adjust start value, if req'd
    pInterval = 5 #adjust interval value, if req'd
    if (rec == 0):
        rec = pStart
    else:
        rec = rec + pInterval
    return rec
expression
autoIncrement(ID)
expected result------------
ID
11
12
13
14
15
(sorry my bad English)Thank
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

Just use the field calculator rather than running the script... or copy and edit it exactly


... sort of retired...

View solution in original post

4 Replies
DanPatterson
MVP Esteemed Contributor

replace accented characters with the field calculator  not closed, you should close old threads if they were answered

/blogs/dan_patterson/2016/08/14/script-formatting  for code formatting so that line numbers can be referenced

What result did you get?  You only posted what you got.


... sort of retired...
0 Kudos
DavidPike
MVP Frequent Contributor

You're passing 'ID' into 'def autoIncrement():' - which has no input parameters.

expression
autoIncrement()

0 Kudos
DanPatterson
MVP Esteemed Contributor

Just use the field calculator rather than running the script... or copy and edit it exactly


... sort of retired...
JoeBorgione
MVP Esteemed Contributor
0 Kudos