How to recreate a sequential field value using ObjectID value

1046
13
Jump to solution
05-05-2023 07:29 AM
Labels (2)
AndrewAidt2
New Contributor III

I am trying to get an empty unique ID field populated. The field is CarteID. I want a prefix of SSP and use the ObjectID field. Example: ObjectID is 10234 - I want the CarteID to be SSP10234. Using Python 3, how do I use the field calculator to populate this field. What Expression do I use?

Then, going forward, is there a way to automatically populate this field when someone adds a new feature?

Thank you!

0 Kudos
1 Solution

Accepted Solutions
RhettZufelt
MVP Frequent Contributor

OIC your issue now, yeah, that is a line number automatically inserted by Pro, NOT part of the code.

With line numbers off, should look more like this (with nothing in the Code Block section):

RhettZufelt_2-1683310435374.png

 


R_

View solution in original post

13 Replies
by Anonymous User
Not applicable

The following should work in python:

"SSP" + !OBJECTID! 

 

As for automatically populating the field moving forward I would suggest an attribute rule.  Something like this should do the trick. The Insert Trigger ensures that the field is only calculated when a new feature is created.

SHartholt_0-1683298275351.png

 

AndrewAidt2
New Contributor III

I am new to Python. How do I put this in the field calculator? What expression do I use? When I put 

"SSP" + !OBJECTID! 

in the Code Block I get an error: 2 parameters are missing or invalid.

Thanks!

0 Kudos
by Anonymous User
Not applicable

Are you using arcmap or arcgis pro? Either way, when you open the attribute table right click on the field name (CarteID) click calculate field/Field Calculator and paste in the code. Make sure that the expression type/parser is python.

0 Kudos
AndrewAidt2
New Contributor III

I am using Pro. I pasted the code and I get the error I mentioned above.Screenshot 2023-05-05 112359.png

0 Kudos
RhettZufelt
MVP Frequent Contributor

RhettZufelt_0-1683300736777.png

 

0 Kudos
AndrewAidt2
New Contributor III

Screenshot 2023-05-05 113900.png

0 Kudos
RhettZufelt
MVP Frequent Contributor

Working fine in 2.9.3 and 3.1.1.

It appears as if it doesn't like the first double quote in your syntax for some reason (perhaps copy/pasted in windoze).  Try replacing or just use single quotes, they work as well.

 

RhettZufelt_0-1683301793280.png

RhettZufelt_1-1683301840632.png

 

R_

0 Kudos
AndrewAidt2
New Contributor III

What is the blue 1 you have at the beginning? I don't get that.

0 Kudos
AndrewAidt2
New Contributor III

Mine is black...

0 Kudos