Looking for a way to update coded values domains for my AGOL feature service

979
5
06-11-2019 08:52 AM
by Anonymous User
Not applicable

I have an inventory system setup for our Sign Department and it generates a list of what's in stock every night which I would like to use as CVD for our maintenance reports on our sign layer. Since this list changes daily I need a way to update my feature service with the updated data. Any help or examples would be very appreciated. 

Thanks!

0 Kudos
5 Replies
RobertBorchert
Frequent Contributor III

So the domain values would change every night?  Are the people out there looking at the reports making  changes to those domain fields?

If they are not why even use domains at all.

0 Kudos
by Anonymous User
Not applicable

If a Sign in inventory has a qty of 0 it is pulled from the available signs shown in the drop down list for our maintenance reports so that the drop down doesn't become massive. Once they complete maintenance the sign they chose from the drop down is subtracted from the current inventory table using another python script.

0 Kudos
RobertBorchert
Frequent Contributor III

So you domain is the name of the sign?

Why not just a definition query on the inventory level to not show those with a quantity of 0?

If the worker changes the inventory level to 0 it is removed from the list when they save

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Maybe you can try the following code to update the domain values of a service

Try it on a test service before updating your production service.

item = gis.content.get('ItemID')

#get the FeatureLayerCollection
flc = FeatureLayerCollection.fromitem(item)

#define the update dictionary
update_dict = {
        "fields": [
            {
                "name": "fieldx",
                "domain": {
                    "type": "codedValue",
                    "name": "Signs",
                    "codedValues": [
                        {
                            "name": "Option A",
                            "code": "type_a"
                        },
                        {
                            "name": "Option B",
                            "code": "type_b"
                        },
                        {
                            "name": "Option C",
                            "code": "type_c"
                        }
                    ]
                }
            }
        ]
}

#update the featureservice definition
flc.manager.update_definition(update_dict)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Please let us know if it works.

0 Kudos
TregChristopher
Occasional Contributor

I get a message:

{'success': True}

 but when I look at the layer interface (the list of values) or review the json of the service (.../rest/admin/services/..), nothing has changed. When I do this manually (on the rest/admin/services update definition I have to change the line lasteditdate = " " (removing the date and replacing with quotes with a space following the known issues described in:https://support.esri.com/en/technical-article/000014622) and then the changes are successfully applied.

Wouldn't you also need to include this lasteditdate line in your dictionary?

If so, I've tried something like this (see below) with the same 'success' message but without changes successfully applied.

 

#define the update dictionary
##test using the entire copy of the json of the service
##(as if you were doing it manual update with the .../rest/admin/services/... url for that service)
update_dict = {
        "editingInfo" : {
            "lastEditDate" : " "
        }, 
        "fields": [
            
            {
                "name": "OccurTaxoID",
                "domain": {
                    "type": "codedValue",
                    "name": "cvd_OccurTaxoID",
                    "codedValues": [
                        {
                            "name": "Amphibian!!: Unknown/Other",
                            "code": "-1113"
                        },
                        {
                            "name": "Frog/Toad!!: Unknown/Other",
                            "code": "-1114"
                        },
                        {
                            "name": "Frog/Toad!!: Bullfrog",
                            "code": "-1115"
                        }
                    ]
                }
            }
        ]
}
0 Kudos