Hi, I am trying to use the API to change the display name of the fields in my feature layer. I am getting the following error.
Exception: Unable to update feature service layer definition.
Invalid definition for 'LastEditDate'.
Invalid definition for ESRI.ArcGIS.SDS.Metadata.EditingInfo
(Error Code: 400)
I tried a couple of things I found online to get rid of this error, but was not successful in solving the problem. I read that the LastEditDate must be set to Null, but I do not know where that is stored or how to update it. Thanks in advance for assistance!
Here is my code:
rename_fields_dict = {
'name': 'Station/Location of Site'
}
item_id = 'b343dc10f4b4458cbf0eb5a5e5a51234'
fs_item = gis.content.get(item_id)
layer = gis.content.get(item_id).layers[0]
field_defs = layer.properties["fields"]
str_field = str(field)
for field in field_defs:
display_name = rename_fields_dict.get(str_field, '')
if display_name != '':
field["alias"] = display_name
layer.manager.update_definition(layer.properties)
Solved! Go to Solution.
Hi @sandra555,
You need to use the actual name of the field and update the alias. You are using layer.properties in the update to update ALL properties, you only want to update the fields property. Try below and let us know how you get on.
from arcgis.gis import GIS
## access ArcGIS Online
agol = GIS("home")
## get the Feature Service as an Item object
fs_item = agol.content.get("FS_ITEM_ID")
## get the Feature Layer as a FeatureLayer object
layer = fs_item.layers[0] # 0 is the first layer in the feature service
## define the field dictionary
rename_field_dict = {
"name" : "THE_FIELD_NAME_TO_UPDATE_ALIAS_FOR",
"alias" : "HOW_I_WANT_THE_FIELDNAME_TO_BE_DISPLAYED"
}
## apply the update to the fields property
layer.manager.update_definition({"fields" : [field_dict]})
Hi @sandra555,
You need to use the actual name of the field and update the alias. You are using layer.properties in the update to update ALL properties, you only want to update the fields property. Try below and let us know how you get on.
from arcgis.gis import GIS
## access ArcGIS Online
agol = GIS("home")
## get the Feature Service as an Item object
fs_item = agol.content.get("FS_ITEM_ID")
## get the Feature Layer as a FeatureLayer object
layer = fs_item.layers[0] # 0 is the first layer in the feature service
## define the field dictionary
rename_field_dict = {
"name" : "THE_FIELD_NAME_TO_UPDATE_ALIAS_FOR",
"alias" : "HOW_I_WANT_THE_FIELDNAME_TO_BE_DISPLAYED"
}
## apply the update to the fields property
layer.manager.update_definition({"fields" : [field_dict]})
Hi Clubdebambos, Thanks for your example. I have it working now!