<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Update all View Layers to Match Updated Hosted Feature Layer Fields in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1346673#M9250</link>
    <description>&lt;P&gt;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 &amp;amp; 26-34:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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!')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ideas? thoughts? alternative solutions? thanks!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Nov 2023 14:10:10 GMT</pubDate>
    <dc:creator>GIS_utahDEM</dc:creator>
    <dc:date>2023-11-07T14:10:10Z</dc:date>
    <item>
      <title>Update all View Layers to Match Updated Hosted Feature Layer Fields</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1346673#M9250</link>
      <description>&lt;P&gt;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 &amp;amp; 26-34:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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!')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ideas? thoughts? alternative solutions? thanks!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 14:10:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1346673#M9250</guid>
      <dc:creator>GIS_utahDEM</dc:creator>
      <dc:date>2023-11-07T14:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Update all View Layers to Match Updated Hosted Feature Layer Fields</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1346745#M9252</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/431239"&gt;@GIS_utahDEM&lt;/a&gt;, What's the format of your `fields` variable? It will need to be a list of key, value pairs.&lt;BR /&gt;&lt;BR /&gt;dict_fields = [{"name": fieldName, "visible":True/False},...].&lt;/P&gt;&lt;P&gt;Here's a small example that updates the fields of an existing view by iterating through the original layers fields and adding only a subset.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

# Set up some variables
params = {
    "view_id": "e1fa73f21d0e42e9b208114ccdce04a1", # id of existing view
    "include_fields": ["apn", "usetype", "roll_landv"] # limit the fields we want in the view to these three
}
# connect
portal = GIS(username="USERNAME", password="PASSWORD")
print(f"logged in to {portal.properties.name} as {portal.properties.user.username}")

# Get the existing view by item id
view = portal.content.get(params["view_id"])

# Get a reference to the source feature layer,
source_fl = view.related_items("Service2Data")[0]

# Get a list of all the fields on the source feature layer
source_flds = source_fl.layers[0].properties.fields

# create a list of key, value (name, visible) objects representing the subset of fields from the source layer we want included in the view
vis_flds = [{"name":f"{f.name}", "visible": True} if f.name in params["include_fields"] or f.type == "esriFieldTypeOID" else {"name":f"{f.name}", "visible": False} for f in source_flds]

# update the view definition with our new list
view.layers[0].manager.update_definition({"fields": vis_flds})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 07 Nov 2023 16:27:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1346745#M9252</guid>
      <dc:creator>Mark_T</dc:creator>
      <dc:date>2023-11-07T16:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Update all View Layers to Match Updated Hosted Feature Layer Fields</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1346824#M9253</link>
      <description>&lt;P&gt;This is what "fields" looks like:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GIS_utahDEM_0-1699380630305.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/85281i217ADDE5E5BCCE7C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GIS_utahDEM_0-1699380630305.png" alt="GIS_utahDEM_0-1699380630305.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is what "dict_fields" looks like&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GIS_utahDEM_1-1699380690543.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/85282i366009EC0919219C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GIS_utahDEM_1-1699380690543.png" alt="GIS_utahDEM_1-1699380690543.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looping through each view, with the specific information about that view captured in lines 19-22&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 18:12:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1346824#M9253</guid>
      <dc:creator>GIS_utahDEM</dc:creator>
      <dc:date>2023-11-07T18:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Update all View Layers to Match Updated Hosted Feature Layer Fields</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1346850#M9254</link>
      <description>&lt;P&gt;If you want all the fields and not a subset then you should be able to do something like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;layerTags = [county_name, view_name, "UCIP", "View Layer"]

# Populate the update_dict with tags and fields
dict_fields = [{"name":f"{f.name}", "visible":True} for f in fields]
print(dict_fields)
update_dict = {"tags": layerTags, "fields": dict_fields}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 07 Nov 2023 19:18:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1346850#M9254</guid>
      <dc:creator>MarkTorrey</dc:creator>
      <dc:date>2023-11-07T19:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Update all View Layers to Match Updated Hosted Feature Layer Fields</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1347102#M9261</link>
      <description>&lt;P&gt;Thanks! Would that impact anything about the fields (i.e. domains/lists), I'm not very familiar with this and from how I understand the code it would only carry over the field names and nothing else?&lt;/P&gt;&lt;P&gt;I am just trying to update all the views to match the original -- so if I add or delete a few fields on the original, I want to be able to run this so all the views stay up to date.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 13:25:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1347102#M9261</guid>
      <dc:creator>GIS_utahDEM</dc:creator>
      <dc:date>2023-11-08T13:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Update all View Layers to Match Updated Hosted Feature Layer Fields</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1347116#M9262</link>
      <description>&lt;P&gt;This is just telling the layer views what fields to make visible and won't affect any other properties of the fields. You can run this anytime the source feature service is updated.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 13:41:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/update-all-view-layers-to-match-updated-hosted/m-p/1347116#M9262</guid>
      <dc:creator>MarkTorrey</dc:creator>
      <dc:date>2023-11-08T13:41:32Z</dc:date>
    </item>
  </channel>
</rss>

