<?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 Re: create_view is changing service definition on parent item in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1706239#M11957</link>
    <description>&lt;P&gt;I upgraded my API to 2.4.3 and it appears to have the same issue. With your approach, redefining the JSON for the missing layers, customized pop ups are wiped out (as expected given the code). Given my workflow of creating views instead of inserting layers, I can just copy all the JSON before running create_view and then if any layers are missing, replace all the JSON with the original.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Get feature service
source_item = portal.content.get("42...3ec")

# Get a FeatureLayerCollection from the item
source_flc = FeatureLayerCollection.fromitem(source_item)

# Get source_item JSON before creating the view
item_data_backup = source_item.get_data()

backup_layers = {
    lyr["id"]: lyr
    for lyr in item_data_backup.get("layers", [])
}

backup_ids = set(backup_layers.keys())

# Create the view layer
vw_name = "tracks_2"
view_item = source_flc.manager.create_view(name=vw_name)

# Get the source_item JSON after creating the view
item_data = source_item.get_data()

current_ids = {
    lyr["id"]
    for lyr in item_data.get("layers", [])
}

# Find missing layer IDs
missing_ids = backup_ids - current_ids

if missing_ids:

    print(
        f"Detected {len(missing_ids)} missing layer(s) in source item JSON. "
        "Restoring from backup."
    )

    print(f"Missing layer IDs: {sorted(missing_ids)}")

    # Restore the entire layers array from backup
    # in the same order as the service definition
    item_data["layers"] = [
        backup_layers[fl.properties.id]
        for fl in source_flc.layers
        if fl.properties.id in backup_layers
    ]

    source_item.update(
        item_properties={"text": item_data}
    )

    print("Finished restoring parent layer JSON from backup")

else:
    print("No missing layers")&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 04 Jun 2026 13:39:28 GMT</pubDate>
    <dc:creator>JamesTurner2</dc:creator>
    <dc:date>2026-06-04T13:39:28Z</dc:date>
    <item>
      <title>create_view is changing service definition on parent item</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1705704#M11946</link>
      <description>&lt;P&gt;I am trying to create a hosted feature layer view that contains 2 out of 3 layers in a service. When I run create_view, my view is created correctly with 2 layers, but for some reason it is effecting the source item as well. When I go to the source item page, I only see two layers listed, however, all 3 layers are still listed if I look at the service URL. Not sure what's going on here, if I create a second view with different layers, the source item returns to normal.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;## get feature service
source_item = portal.content.get("9ab20e7f7f7d4a89b0d6c053a03e6305")

# Get a FeatureLayerCollection from the item
source_flc = FeatureLayerCollection.fromitem(source_item)

# Create dict of layers in service name:url
layer_lookup = {
    lyr.properties.name: lyr
    for lyr in source_flc.layers
}

# Configuration for each layer in the new view
layer_configs = {
    "Tracks": {
        "query": "inspection_year = '2025'",
        "hidden_fields": ["agency", "updates_req"]
    }
    ,
    "Clubs": {
        "query": "insp_years = 'Even'",
        "hidden_fields": ["closed_miles"]
    }
}

# Use dict keys from layer_config to get service URL to use in view_layers, this defines which layers are included
view_layers = [
    layer_lookup[name] for name in layer_configs.keys()
]

# Create the view layer
vw_name = "2025_Inspection_Tracks"
view_capabilities = "Query,Create,Update,Delete,Editing,Sync" 
view_item = source_flc.manager.create_view(name=vw_name
                                    , view_layers=view_layers
                                    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2026 19:14:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1705704#M11946</guid>
      <dc:creator>JamesTurner2</dc:creator>
      <dc:date>2026-06-02T19:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: create_view is changing service definition on parent item</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1705872#M11948</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/593338"&gt;@JamesTurner2&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;What version of the API are you using? I had this issue before but I haven't checked if it is still happening in the latest version (2.4.3 at time of writing).&lt;/P&gt;&lt;P&gt;The JSON data behind the service is getting manipulated. If you look at the original service in AGO Assistant or print the item object get_data() dictionary to screen, you will see only two layer defined.&lt;/P&gt;&lt;P&gt;Similar happens with the insert_layer(). I have a video &lt;A href="https://youtu.be/jOzrUdyCKCk" target="_self"&gt;here&lt;/A&gt; detailing how to fix that, and a it would be similar for here. See code below.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

## access AGOL
agol = GIS("home")

## get the item object
item = agol.content.get("FS_ITEM_ID")

## item data layer dictionary template
lyr_dict = {
    "id" : None,
    "blendMode" : "normal",
    "layerDefinition" : {},
    "disablePopup" : False,
    "popupInfo" : {
        "popupElements" : [
            {
                "type" : "fields",
                "fieldInfos" : None
            }
        ]
    }
}

## get the FeatureLayer object - USE THE INDEX FOR THE MISSING LAYER
fl = flc.layers[0]

## update the id key
lyr_dict["id"] = fl.properties.id

## update the layerDefinition key (symbology))
lyr_dict["layerDefinition"]["drawingInfo"] = fl.properties.drawingInfo

## get the field info for the popup
field_infos = []
for field in fl.properties.fields:
    field = dict(field)
    field_dict = {
        "fieldName" : field["name"],
        "isEditable" : field["editable"],
        "label" : field["alias"],
        "visible" : True
    }
    field_infos.append(field_dict)

## apply the field infos
lyr_dict["popupInfo"]["popupElements"][0]["fieldInfos"] = field_infos

## get the item JSON data
item_data = item.get_data()

## update layers
item_data["layers"] = item_data["layers"] + [lyr_dict]

## update the Item
update_dict = {
    "text" : item_data
}

item.update(
    item_properties = update_dict
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2026 07:44:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1705872#M11948</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2026-06-03T07:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: create_view is changing service definition on parent item</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1706041#M11951</link>
      <description>&lt;P&gt;I am using version 2.4.1.1 on Enterprise 11.5. Your code helped me get to a solution, I had recognized that the issue was in the JSON but couldn't figure out how to fix it! Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2026 17:52:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1706041#M11951</guid>
      <dc:creator>JamesTurner2</dc:creator>
      <dc:date>2026-06-03T17:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: create_view is changing service definition on parent item</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1706239#M11957</link>
      <description>&lt;P&gt;I upgraded my API to 2.4.3 and it appears to have the same issue. With your approach, redefining the JSON for the missing layers, customized pop ups are wiped out (as expected given the code). Given my workflow of creating views instead of inserting layers, I can just copy all the JSON before running create_view and then if any layers are missing, replace all the JSON with the original.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Get feature service
source_item = portal.content.get("42...3ec")

# Get a FeatureLayerCollection from the item
source_flc = FeatureLayerCollection.fromitem(source_item)

# Get source_item JSON before creating the view
item_data_backup = source_item.get_data()

backup_layers = {
    lyr["id"]: lyr
    for lyr in item_data_backup.get("layers", [])
}

backup_ids = set(backup_layers.keys())

# Create the view layer
vw_name = "tracks_2"
view_item = source_flc.manager.create_view(name=vw_name)

# Get the source_item JSON after creating the view
item_data = source_item.get_data()

current_ids = {
    lyr["id"]
    for lyr in item_data.get("layers", [])
}

# Find missing layer IDs
missing_ids = backup_ids - current_ids

if missing_ids:

    print(
        f"Detected {len(missing_ids)} missing layer(s) in source item JSON. "
        "Restoring from backup."
    )

    print(f"Missing layer IDs: {sorted(missing_ids)}")

    # Restore the entire layers array from backup
    # in the same order as the service definition
    item_data["layers"] = [
        backup_layers[fl.properties.id]
        for fl in source_flc.layers
        if fl.properties.id in backup_layers
    ]

    source_item.update(
        item_properties={"text": item_data}
    )

    print("Finished restoring parent layer JSON from backup")

else:
    print("No missing layers")&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 04 Jun 2026 13:39:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1706239#M11957</guid>
      <dc:creator>JamesTurner2</dc:creator>
      <dc:date>2026-06-04T13:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: create_view is changing service definition on parent item</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1706256#M11958</link>
      <description>&lt;P&gt;Yes, exactly. Nicely done.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2026 14:57:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-view-is-changing-service-definition-on/m-p/1706256#M11958</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2026-06-04T14:57:24Z</dc:date>
    </item>
  </channel>
</rss>

