AnsweredAssumed Answered

Sequential field calculation with Python

Question asked by greenk8ty on Jun 1, 2016
Latest reply on Jun 1, 2016 by Christian_Wells-esristaff


I'm trying to field calculate some records that have a null value.  I used the following code from the ESRI help section on sequential calculations.  It worked!  Now I need to modify the script a bit.  This code gives me a sequential order of single digits.  I would like to have some zeros before the new assigned digit.  0001 instead of just 1.  How do I add the three zeros before the assigned digit?  I would like a four digit value in the end.  0001, 0002, 0003, etc.

 

Thanks!

 

Here's the python code I used:

 

Parser:

Python

 

Expression:

autoIncrement()

 

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

Outcomes