Hello! I have a Hosted Feature Layer with a large number of views (one for each jurisdiction in my state). I have made some updates to the main hosted feature layer (added a couple of fields), and I want to update all of the hosted feature layer views to match. I am trying to update by getting the fields from the main layer and using an update dictionary. My code runs, but when I open a view layer in AGOL the fields have not been updated. I've attached the relevant code I'm using below, particularly in rows 1-2 & 26-34:
import json
fields = ucip_properties.fields
# Loop through the regional division to create the views
for index, county in enumerate(counties_munis):
county_name = counties_munis.features[index].attributes['NAME']
print(county_name)
view_name = 'UCIP_' + county_name + "_LIVE_View"
print(view_name)
# Get the geometry for the regions
view_geom = counties_munis.features[index].geometry.get('rings')
name_avail = cm.is_service_name_available(service_name = view_name,service_type = "featureService")
# Check if view exists
if name_avail == True:
# CODE TO CREATE VIEW
else:
print(view_name," Exists")
# Search for newly created View
view_search = my_agol.content.search(view_name)[0]
view_flc = FeatureLayerCollection.fromitem(view_search)
service_layer = view_flc.layers[0]
layerTags = [county_name,view_name,"UCIP","View Layer"]
# Populate the update_dict with tags and fields
dict_fields = json.loads(f'{fields}')
print(dict_fields)
update_dict = {"tags":layerTags,"fields":dict_fields}
#print(service_layer.properties.tags)
# Update the definition to include the tags
view_search.update(update_dict)
print("Added tags to ",view_name)
print('Done!')
ideas? thoughts? alternative solutions? thanks!!