According to the documentation: https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#viewmanager, to create a hosted feature layer view in code with the overwrite option:
create(name, spatial_reference=None, extent=None, allow_schema_changes=True, updateable=True, capabilities='Query', view_layers=None, view_tables=None, *, description=None, tags=None, snippet=None, overwrite=None, set_item_id=None, preserve_layer_ids=False, visible_fields=None, query=None)¶
overwrite Optional Boolean. If true, the view is overwritten, False is the default.
In my code:
the_view = the_item.view_manager.create(name=the_view_name, view_layers=the_layers, overwrite=True)
Throws an error:
local variable 'logging' referenced before assignment
and does not complete.
The same issue is exposed with creating the view using this method:
flc = FeatureLayerCollection.fromitem(the_item)
the_view = flc.manager.create_view(name=the_view_name, view_layers=the_layers, overwrite=True)
Can someone lend me a hand?
TIA
Ah, okay. So, right now are you doing this manually?
If all that's changing in the source data is the addition/removal of a few fields here and there, I think you can just:
Hopefully, I've understood what you're needing to do.
We are adding and removing layers to the source Hosted Feature Layer. The itemID of the Hosted Feature Layer does not change. However, when you add/remove layers to a Hosted Feature Layer, the supporting Hosted Feature Layer Views get corrupted because the indexes of the layers in the Hosted Feature Layer have changed.
We cannot simply repair the source layers in the Hosted Feature Layer View to point to the correct layer in the Hosted Feature Layer, because the Views are created in code and are not supported/editable in the AGOL UI. That's why I was hoping "Overwrite=True" would work- we could simply recreate the View using the same code I used to construct the View in the first place. The View itemID would get preserved and apps that consume the View would be none-the-wiser.
so yeah, we're trying to modify the Views in code. Cheers.