Select to view content in your preferred language

Change the name/display name of a GUID field /relationship

306
1
11-08-2023 01:10 PM
IB3
by
Regular Contributor

Hi, 

I am using this script to change the name/display name of a GUID field in AGOL using a notebook + the name and display name of a relationship. At the end, I get a message that the script was successful, but when I look at the fields in the table in the hosted feature layer, I dont see those changes. any idea why?

 

from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection

# Connect to your ArcGIS Online organization or Portal for ArcGIS
gis = GIS("home")

# Access the hosted feature layer
item = gis.content.get("223afb0dadeb432d9ab1a661e1a8116f")
feature_layer_collection = FeatureLayerCollection.fromitem(item)

# Access the specific table within the feature layer
table = feature_layer_collection.tables[0] # Adjust the index if there are multiple tables

# Change the name and display name of the GUID field
fields = table.properties.fields
for field in fields:
if field["type"] == "esriFieldTypeGUID" and field["name"] == "furnitureguid":
print("Found the field with the name 'furnitureguid' and type 'esriFieldTypeGUID'.")
print("Updating the name and display name of the field to 'landassetsguid'.")
field["name"] = "landassetsguid"
field["alias"] = "Land Assets GUID" # Modify the display name
# Convert the fields list to a dictionary
fields_dict = [dict(field) for field in fields]
try:
table.manager.update_definition({"fields": fields_dict})
print("Successfully updated the name and display name of the GUID field.")
except Exception as e:
print(f"An error occurred while updating the field: {e}")

# Change the name and display name of the relationship
relationships = table.properties.relationships
for relationship in relationships:
if relationship["name"] == "Furniture":
print("Found the relationship with the name 'Furniture'.")
print("Updating the name and display name of the relationship to 'Land Assets'.")
relationship["name"] = "Land Assets"
relationship["name"] = "Land Assets" # Modify the display name
# Convert the relationships list to a list of dictionaries
relationships_dict = [dict(rel) for rel in relationships]
try:
table.manager.update_definition({"relationships": relationships_dict})
print("Successfully updated the name and display name of the relationship.")
except Exception as e:
print(f"An error occurred while updating the relationship: {e}")

/opt/conda/lib/python3.9/site-packages/arcgis/gis/__init__.py:703: UserWarning: You are logged on as Isabelle_B with an administrator role, proceed with caution.
  warnings.warn(
 
Found the field with the name 'furnitureguid' and type 'esriFieldTypeGUID'.
Updating the name and display name of the field to 'landassetsguid'.
Successfully updated the name and display name of the GUID field.
Found the relationship with the name 'Furniture'.
Updating the name and display name of the relationship to 'Land Assets'.
Successfully updated the name and display name of the relationship.
0 Kudos
1 Reply