Publishing layers to AGOLE

981
2
11-25-2020 05:48 AM
inolaroch
New Contributor III
 
Tags (3)
0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

Per the ArcPy docs, the getWebLayerSharingDraft method takes an optional parameter layers_and_tables.

A list of layers and tables from the map. If left blank, the entire map will be published. This parameter allows you to choose a subset of layers and tables from the map to publish. The layers and tables must be from the same map that is being published.

Since you already have your map as the object m, you just need to call m.listLayers() to retrieve the list of layers in your map.

With that, you could easily nest your existing code in a for loop, somewhat like this:

lyrs = m.listLayers()

for lyr in lyrs:
    service = lyr.name
    sharing_draft = m.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", service, lyr)
    ...

 Note that the variable service has to be defined inside the loop, otherwise each layer will attempt to publish with the same service name.

- Josh Carlson
Kendall County GIS
inolaroch
New Contributor III

Thank you Mr Carlson for your help i will try it.

Kind Regards,

0 Kudos