Create List (Domain) again after previously deleted it.

334
1
01-24-2021 07:35 PM
Labels (1)
frhilyana_geo11
New Contributor III

I've previously created domain in ArcGIS Online by clicking the 'create list'. But then I deleted the list because I decided not to apply domain to the attribute list. Now I want to apply the domain back. However, the 'create list' button is no longer there. How to create list again after previously deleted it?

Attached together is the screenshot

0 Kudos
1 Reply
jcarlson
MVP Notable Contributor

I've definitely had this happen, too. Perhaps someone else has an alternate method, but the only way I could re-apply a list was to use Python to directly edit the service properties, as described in the Feature Layer Manager section of the python API docs.

A big caveat: direct modifications to the service JSON can be risky. The service won't always let you make modifications if your input isn't formatted correctly, but it's quite possible to apply edits to the wrong layer, field, etc.

Also: to help you format your update, refer to the JavaScript docs for the Update Definition command, especially example 6, in which a field domain is edited.

Your code might look something like this:

from arcgis.gis import GIS
from arcgis.features.managers import FeatureLayerManager

gis = GIS('your-portal-url', 'your-username')

flm = FeatureLayerManager.fromitem(gis.content.get('your-layer-itemID'), your-layer-index)

update_json = {
  "fields": [
    {
      "name": "your-field",
      "domain": {
        "type": "codedValue",
        "name": "domain-name",
        "codedValues": [
          {
            "name": "Coded Value 1",
            "code": "Code_1"
          },
          ...
          }
        ]
      },
      "defaultValue": null
    }
  ]
}

flm.update_definition(update_json)

 

If you prefer using the Portal's interface for modifying your list, it should be possible to use this to establish the existence of the list with only a single value, then go into the Field view in your Portal to add other codes to it.

Good luck!

- Josh Carlson
Kendall County GIS