Select to view content in your preferred language

set a field as unique using arcgis api for python

254
2
Jump to solution
a month ago
Labels (2)
MartinPeak
New Contributor II

Can you set a field as unique using the arcgis rest api for python?

MartinPeak_0-1716263353621.png

 

0 Kudos
1 Solution

Accepted Solutions
MobiusSnake
MVP

You can, enabling unique values means adding an index with a unique constraint to the field.  To do this in the API you'll want to call the FeatureLayerManager's add_to_definition() function, passing in something like this:

 

 

{"indexes":[
  {"fields":"MyField",
   "isUnique":True,
   "description":"For uniqueness"}
]}

 

 

 

View solution in original post

2 Replies
MobiusSnake
MVP

You can, enabling unique values means adding an index with a unique constraint to the field.  To do this in the API you'll want to call the FeatureLayerManager's add_to_definition() function, passing in something like this:

 

 

{"indexes":[
  {"fields":"MyField",
   "isUnique":True,
   "description":"For uniqueness"}
]}

 

 

 

MartinPeak
New Contributor II

thanks that works - this is the code:

layer = published_item.layers[0]
layer.manager.add_to_definition({
    "indexes": [
        {
            "fields": "some_id",
            "isUnique": True,
            "description": "For uniqueness"
        }
    ]
})