Select to view content in your preferred language

Alphabetically sort domain lists when over 500?

371
6
2 weeks ago
luckachi
Frequent Contributor

I have a hosted feature layer that contains four layers, each with a field containing more than 500 domain values (invasive species). Is there any way to sort these domain lists alphabetically? Right now, managing the lists is very difficult, since dragging and dropping domain values between pages is extremely time-consuming and nearly impossible to do efficiently.

0 Kudos
6 Replies
Katie_Clark
MVP Regular Contributor

I don't think there's a GUI option for this, but I would probably approach this by modifying the JSON in the REST endpoint and copy/pasting between layers.

You can do this directly in ArcGIS Online, but it's also quite easy to do with ArcGIS Assistant:
https://assistant.esri-ps.com/

Best,
Katie

If this post helped you, please consider giving a kudos and/or marking as the accepted solution. Thanks!
0 Kudos
luckachi
Frequent Contributor

Hi Katie - I am assuming the domain list would show up somewhere in the JSON Editor in the ArcGIS Assistant? 

0 Kudos
Katie_Clark
MVP Regular Contributor

Yup! It's in the "Data" section of the feature layer's JSON. Ctrl + F is your friend, search for "domain" and the applicable section should be easy to locate.

Screenshot 2026-05-14 110021.jpg

 

Also, if you find yourself needing to work with JSON a lot, I've found this free online tool very helpful! (and there are tons of similar ones out there, I'm sure). Copy/paste the JSON into the text view and then you can navigate within "Tree" view to help make sense of it all. 

https://jsoneditoronline.org/

Best,
Katie

If this post helped you, please consider giving a kudos and/or marking as the accepted solution. Thanks!
0 Kudos
luckachi
Frequent Contributor

Unfortunately none of the domains show up in the Assistant 

Untitled-1.jpgScreenshot 2026-05-14 112818.png

but I can see it in the ArcGIS REST Services Directory. Unfortunately, this still requires me to go through the entire tree and manually cut/paste each species into the correct order. 

luckachi_1-1778772603793.png

 

0 Kudos
Katie_Clark
MVP Regular Contributor

Honestly, this is one of the places where AI is the most useful/least controversial! haha. Ask ChatGPT to alphabetize the JSON list. Definitely do a thorough review, but still beats manually moving them all around yourself!

As for the JSON not showing in ArcGIS Assistant for you....it might be related to how the layer was initially created and published. I seem to remember JSON structures being slightly different for features that were published from Pro vs. created in AGOL directly, but not 100% sure off the top of my head... 


Best,
Katie

If this post helped you, please consider giving a kudos and/or marking as the accepted solution. Thanks!
RhettZufelt
MVP Notable Contributor

Do you have access to Map or Pro?  There are tools in both to sort/export domain tables, just can't use it to update the hosted data.

I do this with arcpy and the python API if you have access to them.  Just need to get them into a sorted table with Code and Description.  Then I use the following code to get it into the correct format:

def CreateDict(fieldname,domainname):
    global update_dict
    update_dict = {"fields": [
       {
         "name": fieldname,
         "domain" :{"type" : "codedValue", "name" : domainname,
         "codedValues" :[
    {"name" : "Pathway", "code"  :  "Pathway"}
    ]}}]}
    

    infc = BASE + os.sep + 'domaintable'    # sorted table with domain Code and Desc.
    with arcpy.da.SearchCursor(infc, ["Code","Street"]) as cursor:
            for row in cursor:
                update_dict['fields'][0]['domain']['codedValues'] += [{"name" : row[0] , "code" :  row[1]}]

In this case, I am adding "Pathway" as I need it in my list, but is not in the table and will be at the top of the domain list.
this will format the update_dict to the proper format, then I use the API to get the layer and update it.

Example Output for the proper format:

update_dict = {"fields": [
    {
      "name": "Street", 
      "domain" :{"type" : "codedValue", "name" : "Streetnames",
      "codedValues" :[
{"name" : "Pathway", "code"  :  "Pathway"},
{"name" : "89 PR SE", "code"  :  "89 PR SE"},
{"name" : "952 PR SE", "code"  :  "952 PR SE"},
{"name" : "974 PR SE", "code"  :  "974 PR SE"},
{"name" : "9th St", "code"  :  "9th St"},
{"name" : "Aaron Dr", "code"  :  "Aaron Dr"},
{"name" : "Abbot St", "code"  :  "Abbot St"},
{"name" : "Abert Ave", "code"  :  "Abert Ave"},
{"name" : "Acacia Ave", "code"  :  "Acacia Ave"},
{"name" : "Ada St", "code"  :  "Ada St"},
{"name" : "Adair Ct", "code"  :  "Adair Ct"},
{"name" : "Adair Dr", "code"  :  "Adair Dr"},
{"name" : "Adams St", "code"  :  "Adams St"},
{"name" : "Addison St", "code"  :  "Addison St"},
{"name" : "NA", "code"  :  "NA"}
     
]}}]}

 

lyr = my_agol.content.get('xxxxxxItemIDxxxxxxxxx').layers[0]    # get the layer to update
update = lyr.manager.update_definition(update_dict)

 

 R_

PS, unless there is a need to have the code different that the description, would highly suggest you keep them the same (as in my example above, or @Katie_Clark's example) as you will have better results with fewer issues in the future.   Domains don't all work the same in each client.  sometimes it searches code, sometimes domain, sometimes displays one and not the other.  The only way for it to be 'bulletproof' is if they are both the same.

0 Kudos