<?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 View creation iteration losing source feature service in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/view-creation-iteration-losing-source-feature/m-p/1691336#M68222</link>
    <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;I'm attempting this loop but on all the unique values within a a field in a feature service, and it works for the first 4 times on the list but on the 4th or 3rd iteration it appears to lose the feature service that its pointed towards. Any clue whats happening here?&lt;/P&gt;&lt;P&gt;source code&lt;/P&gt;&lt;LI-CODE lang="c"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
import pandas

import time
## access agol
agol = GIS("home")

## access the feature service item that contains the layers
fs_item = agol.content.get("ITEMID")
url = "  URL "
## create a FeatureLayerCollection object from the feature service item
flc = FeatureLayerCollection.fromitem(fs_item)
queryfields = ["Program"]
grants= flc.layers[0].query()
grantdf = grants.sdf
programs = grantdf['PROGRAM'].unique().tolist()
programs.sort()
print(f"{len(programs)} grant programs: {programs}")

for prog in programs:
starttime = time.perf_counter()
where_clause = "PROGRAM IN ({})".format(','.join(["'{}'".format(prog)]))
fs_item = agol.content.get("ITEMID")
flc = FeatureLayerCollection.fromitem(fs_item)
print (flc)
with arcpy.da.SearchCursor(url, queryfields, where_clause) as cursor:
rows = [row for row in cursor]
print(f" Total Grant in {prog}: {len(rows)}")
new_view = flc.manager.create_view(
name = prog+"_Program",
#select the layer based on its id
view_layers = [flc.layers[0]],
description = f"This layer depicts all awarded grants for the "+prog+f" program.",
tags = prog+", TAG",
snippet = f"PLACEHOLDER",
query = where_clause+" AND (PAYTAMT &amp;gt; 0)"
)
time.sleep(5)
endtime =time.perf_counter()
print(f"Time to process:{(endtime-starttime)}")&lt;/LI-CODE&gt;&lt;P&gt;Error Message&lt;/P&gt;&lt;LI-CODE lang="c"&gt;IndexError                                Traceback (most recent call last)
Cell In[16], line 11
      9     rows = [row for row in cursor]  
     10     print(f" Total Grant in {prog}: {len(rows)}")
---&amp;gt; 11     new_view = flc.manager.create_view(
     12         name = prog+"_=Program",
     13                 #select the layer based on its id
     14         view_layers = [flc.layers[0]],
     18         query = where_clause+" AND (PAYTAMT &amp;gt; 0)"
     19     )
     20 time.sleep(5)
     21 endtime =time.perf_counter()

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\managers.py:3041, in FeatureLayerCollectionManager.create_view(self, name, spatial_reference, extent, allow_schema_changes, updateable, capabilities, view_layers, view_tables, description, tags, snippet, overwrite, set_item_id, preserve_layer_ids, visible_fields, query, folder)
   3038 update_item_data(view_item, item, view_layers)
   3040 item = gis.content.get(res["itemId"])
-&amp;gt; 3041 set_visible_fields_and_query(item, visible_fields, query, gis)
   3043 return item

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\managers.py:3009, in FeatureLayerCollectionManager.create_view.&amp;lt;locals&amp;gt;.set_visible_fields_and_query(item, visible_fields, query, gis)
   3007 if visible_fields or query:
   3008     values = {}
-&amp;gt; 3009     fields = item.layers[0].properties["fields"]
   3010     if visible_fields:
   3011         field_names = [f.lower() for f in visible_fields]

IndexError: list index out of range&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Mar 2026 17:53:19 GMT</pubDate>
    <dc:creator>EvanMarshall2</dc:creator>
    <dc:date>2026-03-18T17:53:19Z</dc:date>
    <item>
      <title>View creation iteration losing source feature service</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/view-creation-iteration-losing-source-feature/m-p/1691336#M68222</link>
      <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;I'm attempting this loop but on all the unique values within a a field in a feature service, and it works for the first 4 times on the list but on the 4th or 3rd iteration it appears to lose the feature service that its pointed towards. Any clue whats happening here?&lt;/P&gt;&lt;P&gt;source code&lt;/P&gt;&lt;LI-CODE lang="c"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
import pandas

import time
## access agol
agol = GIS("home")

## access the feature service item that contains the layers
fs_item = agol.content.get("ITEMID")
url = "  URL "
## create a FeatureLayerCollection object from the feature service item
flc = FeatureLayerCollection.fromitem(fs_item)
queryfields = ["Program"]
grants= flc.layers[0].query()
grantdf = grants.sdf
programs = grantdf['PROGRAM'].unique().tolist()
programs.sort()
print(f"{len(programs)} grant programs: {programs}")

for prog in programs:
starttime = time.perf_counter()
where_clause = "PROGRAM IN ({})".format(','.join(["'{}'".format(prog)]))
fs_item = agol.content.get("ITEMID")
flc = FeatureLayerCollection.fromitem(fs_item)
print (flc)
with arcpy.da.SearchCursor(url, queryfields, where_clause) as cursor:
rows = [row for row in cursor]
print(f" Total Grant in {prog}: {len(rows)}")
new_view = flc.manager.create_view(
name = prog+"_Program",
#select the layer based on its id
view_layers = [flc.layers[0]],
description = f"This layer depicts all awarded grants for the "+prog+f" program.",
tags = prog+", TAG",
snippet = f"PLACEHOLDER",
query = where_clause+" AND (PAYTAMT &amp;gt; 0)"
)
time.sleep(5)
endtime =time.perf_counter()
print(f"Time to process:{(endtime-starttime)}")&lt;/LI-CODE&gt;&lt;P&gt;Error Message&lt;/P&gt;&lt;LI-CODE lang="c"&gt;IndexError                                Traceback (most recent call last)
Cell In[16], line 11
      9     rows = [row for row in cursor]  
     10     print(f" Total Grant in {prog}: {len(rows)}")
---&amp;gt; 11     new_view = flc.manager.create_view(
     12         name = prog+"_=Program",
     13                 #select the layer based on its id
     14         view_layers = [flc.layers[0]],
     18         query = where_clause+" AND (PAYTAMT &amp;gt; 0)"
     19     )
     20 time.sleep(5)
     21 endtime =time.perf_counter()

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\managers.py:3041, in FeatureLayerCollectionManager.create_view(self, name, spatial_reference, extent, allow_schema_changes, updateable, capabilities, view_layers, view_tables, description, tags, snippet, overwrite, set_item_id, preserve_layer_ids, visible_fields, query, folder)
   3038 update_item_data(view_item, item, view_layers)
   3040 item = gis.content.get(res["itemId"])
-&amp;gt; 3041 set_visible_fields_and_query(item, visible_fields, query, gis)
   3043 return item

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\managers.py:3009, in FeatureLayerCollectionManager.create_view.&amp;lt;locals&amp;gt;.set_visible_fields_and_query(item, visible_fields, query, gis)
   3007 if visible_fields or query:
   3008     values = {}
-&amp;gt; 3009     fields = item.layers[0].properties["fields"]
   3010     if visible_fields:
   3011         field_names = [f.lower() for f in visible_fields]

IndexError: list index out of range&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2026 17:53:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/view-creation-iteration-losing-source-feature/m-p/1691336#M68222</guid>
      <dc:creator>EvanMarshall2</dc:creator>
      <dc:date>2026-03-18T17:53:19Z</dc:date>
    </item>
  </channel>
</rss>

