Select to view content in your preferred language

create_view Does not work if layer ids are not ordered sequentially

06-09-2024 06:40 AM
Labels (1)
Occasional Contributor

Views created programmatically from services that have non-sequential layer ids are unusable. I created a view from this code:

source_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.

0 Kudos
4 Replies
New Contributor III

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 


I'm working on a solution in Python but haven't gotten there yet.


Occasional Contributor

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.

0 Kudos
Occasional Contributor

The 'workaround' offered by the bug-description, is to create the view manually in AGOL.

0 Kudos
Occasional Contributor

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. 

0 Kudos