Views created programmatically from services that have non-sequential layer ids are unusable. I created a view from this code:
source_search = gis.content.search("test_20240608_unique_ids_assigned_all_around")[0]
source_flc = FeatureLayerCollection.fromitem(source_search)
new_view = source_flc.manager.create_view(name="unid_all_around_view")
Source-Service layer ids:
View layer ids:
When the view is opened in the map viewer, the layers are messed up. The Route line layer has become a point layer and one of the point layers (the one with the very long name!) has become a line. A complete mess.
This happens consistently, on more than one platform. It does not happen when views are created manually. Also, create_view works fine when the layers are ordered sequentially 0 to N, top-down.
I've experienced this issue. I believe it is a defect that Esri should correct: create_view fails to index the layers sequentially.
I see you commented on my other thread.
Meanwhile, the workaround is to manually zero-based index the layers in the hosted feature layer using https://ago-assistant.esri.com/
I'm working on a solution in Python but haven't gotten there yet.
It's actually a bug, but I can't scare it up at the moment. The status of the bug is 'As-Designed' which I do not understand.
The 'workaround' offered by the bug-description, is to create the view manually in AGOL.
Thanks. I'll check that out. There is a 'preserve_layer_ids' property in the create_view method, but I haven't gotten it to accept True
create_view(name = viewName, preserve_layer_ids = True) throws an error. Replace True with False and it works but that's the default and not what I want for this.