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:
name | label | ComponentType |
203 | Process Trap Rock Base | ABR |
212 | HMA S0.5 L2 <= 300 SY-inch | ABR |
247 | Process Trap Rock Base | CBR |
256 | HMA S0.5 L2 <= 300 SY-inch | CBR |
276 | 8 in. Reinforced CBR Installation <= 300 SY | CBR |
302 | HMA S0.375 L2 <= 300 SY-inch | SWK |
304 | 5 in. Concrete Sidewalk | SWK |
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!
Solved! Go to Solution.
Hi @JimW
Put in all the ones that do not have a duplicate label and save.
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.
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.
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.
Hi @JimW
Put in all the ones that do not have a duplicate label and save.
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.
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.
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.
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]