ionarawilson

Sequential Number for a Number Field

Discussion created by ionarawilson on Jul 8, 2013
I want to update a record with a sequential number. Every time the user adds a record, the sequence attribute increases by 1. So record digitized for the first time has a sequence number of 1, the second record gets a sequence number of 2, etc. The record has to be selected when this update occurs. The sequence field is of data type number, but I could create a string attribute if necessary. I tried the following but keeps getting a 1 for all the records. What am I doing wrong? Thank you!!!


    filter = 'NOT Sequence IS NULL' #filter for non-Null values
    cur1 = arcpy.UpdateCursor("Stewardship", filter) 

# Iterate through rows and get highest ID values
    high_id = 0
    for row1 in cur1:
        if high_id < row1.Sequence:
            high_id = row1.Sequence


    filter = 'Sequence IS NULL' #filter for Null values
    cur2 = arcpy.UpdateCursor("Stewardship", filter)

    # Iterate through rows and update values
    i = high_id
    for row2 in cur2:
        i += 1
        row2.Sequence = i
        cur2.updateRow(row2)

Outcomes