Hi Community,
I am having issues with trying to create a coded attribute list for a field in a hosted feature layer using python. Here is some background information and some solutions in related posts that I have tried to no avail.
The layer was published directly to AGOL from an .xlsx spreadsheet. I have a script that overwrites the hosted feature layer. When overwriting the hosted feature layer, some of the properties are reset which need to be addressed in the code: Need to make the layer editable again, and need to re-create the attribute list for a field. I need the attribute list to use radio buttons in Field Maps.
Here is the code, everything works great (layer overwrites, capabilities are updated), but when I try to update the feature layer collection definition to create the coded value domain list, it returns:
{'success': True}
But nothing is changed. No error message or anything.
Full code:
#Import Modules
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
print('Modules Imported')
#AGOL variables assigned
user: str = '<username'
pssw = '<password>'
test_itemid = '<itemid>'
test_upload = '<filepath.xlsx>'
#Coded value variables
low_code = 'Low'
low_name = 'Low'
med_code = 'Med'
med_name = 'Med'
#Get the hosted feature layer collection
gis = GIS('<portal_name>', user, pssw)
test_item= gis.content.get(test_itemid)
test_flc = FeatureLayerCollection.fromitem(test_item)
#Overwrite layer and update capabilities with a dictionary
test_flc.manager.overwrite(test_upload)
update_dict1 = {"hasStaticData":False, "capabilities": "Create,Delete,Query,Update,Editing"}
test_flc.manager.update_definition(update_dict1)
print('Updated definition successfully')
#Create a dictionary to use to update the domain list
update_dict2 = {'fields': [{'name': 'Ranking', 'domain': {'type': 'codedValue',
'name': 'Ranking_Domain',
'codedValues': [{'name': med_name,'code': med_code},
{'name': low_name,'code': low_code}]
}}]}
test_flc.manager.update_definition(update_dict2)
Things I have tried:
1) Tried to create a list without Python in AGOL, then tried updating the coded value list to include an additional value. When I create a list in AGOL, then return the domain list it returns the following:
[{
"type": "codedValue",
"name": "Sheet1_Ranking_itemid",
"codedValues": [
{
"name": "Low",
"code": " Low"
},
{
"name": "Med",
"code": " Med "
}
]
}]
I then tried to use this default domain name in a script to add another coded value to the list, where it says it was successful but nothing updates. This test was to see if when I use an existing domain name if it would work, as described in the following: Solved: Re: Updating Feature Service Coded Value Domain wi... - Esri Community
The process for updating an already existing domain list in AGOL is also described in here, but they use ArcGIS Pro to update: How To: Edit Read-Only Domains of a Hosted Feature Layer Using Python in ArcGIS Pro (esri.com)
2) Views are locked: I then found the following piece: Solved: Re: Can't edit Hosted Feature Layer Domains in Arc... - Esri Community
It describes an issue where the feature layer views parameters need to be changed, but I could not access the viewLayerDefinition as my layer does not have views.
Solutions?
I am wondering if the issue resides in
1) limitations from publishing the hosted feature layer right to AGOL instead of using Pro. There are a number of questions/ solutions in other posts, but most of them are publishing from Pro.
2) The layer did not have coded value domains when first published - does the layer need a domain list from the beginning in order to update?
3) Is there another parameter/ capability that I need to update in order to enable a domain list on the layer?
Any help would be greatly appreciated! I have been trying this for a few weeks now without a solution.