Select to view content in your preferred language

Duplicate Labels in a Domain?

783
2
Jump to solution
07-06-2022 12:50 PM
JimW
by
Frequent Contributor

Why can't  you have duplicate labels in a domain in ArcGIS online?  I understand why you can't have duplicate codes but the label is just text.  It shouldn't matter what the label is since the label isn't what is actually stored in the database.  I was able to create a domain in ArcGIS Pro with duplicate labels and publish to AGO.  It seems that if this is an issue in AGO why would I be allowed to publish the layer with a domain that has duplicate labels?

Now I know someone may be wondering why I would want two codes with different values to have the same label.  I'll do my best to explain.  Below is list that I use in Survey123:

namelabelComponentType
203 Process Trap Rock BaseABR
212 HMA S0.5 L2 <= 300 SY-inchABR
247 Process Trap Rock BaseCBR
256 HMA S0.5 L2 <= 300 SY-inchCBR
276 8 in. Reinforced CBR Installation <= 300 SYCBR
302 HMA S0.375 L2 <= 300 SY-inchSWK
304 5 in. Concrete SidewalkSWK

 

This is actually what I use in Survey123 but the first two columns are the actual domain in my bid item table in my hosted feature layer.  In Survey123 the list is filtered based on the type of component the user has selected.  If the user selects ABR they only see rows 203 and 212 and then additional processing occurs like looking up the bid item cost from a CSV file that depends on this selection.  This was originally designed four years ago and has been used successfully since.  However, a new contract was recently awarded and there are now additional bid items and different costs.  Many of the bid items remained the same.  My plan was to assign a new numeric ID and just append these values to my existing bid item domain.  It was going to be a big list but my end users wouldn't see it that way as I could filter it all in survey123 based on the component type and, now, a contract number.  That's when I discovered that I couldn't have duplicate labels in the domain.  

Is there a way to create a new domain and replace an existing domain with the new one?  Any suggestions or hep would be greatly appreciated!  

1 Solution

Accepted Solutions
Clubdebambos
Frequent Contributor

Hi @JimW 

Put in all the ones that do not have a duplicate label and save.

Clubdebambos_0-1657177977505.png

Use the ArcGIS API for Python to print the JSON of the fields to screen.

 

from arcgis import GIS

agol = GIS("home")

item = agol.content.get("***fs_id***")

## get the layer in the feature service that you are interested in
## if there is only one then the index is 0
lyr = item.layers[0]

print(lyr.properties.fields)

 

In a notepad enter the following and then copy and paste the printed JSON where marked below.

{
    "fields" : 
        *** copy and paste JSON here *** 
}

Save the file with .json extension. Scroll through the notepad to the field with the domain you want to update and add in the duplicate labels with unique code. Save the file.

Clubdebambos_1-1657178439426.png

Use the JSON file to update the fields definition.

 

from arcgis import GIS
import json

agol = GIS("home")

item = agol.content.get("***fs_id***")

## open the JSON file
with open(r"C:\path\to\lyr_fields.json") as json_data:
    data = json.load(json_data)

lyr = item.layers[0]

lyr.manager.update_definition(data)

 

These get added to the domains.

Clubdebambos_2-1657178560882.png

If you go to edit manually you will get the duplicate error, you will have to use the API method going forward to add more.

Clubdebambos_3-1657178671045.png

 

~ learn.finaldraftmapping.com

View solution in original post

2 Replies
Clubdebambos
Frequent Contributor

Hi @JimW 

Put in all the ones that do not have a duplicate label and save.

Clubdebambos_0-1657177977505.png

Use the ArcGIS API for Python to print the JSON of the fields to screen.

 

from arcgis import GIS

agol = GIS("home")

item = agol.content.get("***fs_id***")

## get the layer in the feature service that you are interested in
## if there is only one then the index is 0
lyr = item.layers[0]

print(lyr.properties.fields)

 

In a notepad enter the following and then copy and paste the printed JSON where marked below.

{
    "fields" : 
        *** copy and paste JSON here *** 
}

Save the file with .json extension. Scroll through the notepad to the field with the domain you want to update and add in the duplicate labels with unique code. Save the file.

Clubdebambos_1-1657178439426.png

Use the JSON file to update the fields definition.

 

from arcgis import GIS
import json

agol = GIS("home")

item = agol.content.get("***fs_id***")

## open the JSON file
with open(r"C:\path\to\lyr_fields.json") as json_data:
    data = json.load(json_data)

lyr = item.layers[0]

lyr.manager.update_definition(data)

 

These get added to the domains.

Clubdebambos_2-1657178560882.png

If you go to edit manually you will get the duplicate error, you will have to use the API method going forward to add more.

Clubdebambos_3-1657178671045.png

 

~ learn.finaldraftmapping.com
JimW
by
Frequent Contributor

Thanks for the help.  It worked well.  I did have to change one line of the script as the table I mentioned was a table and not a layer.  Line 9 and 12 above became:

lyr = item.tables[0]