I have a multitude of layers in an ArcPro map that I want to upload to AGOL using ArcPy. The following code will upload each layer that includes the name "zone" to a folder in AGOL. However, when I open the layer in AGOL, I see that it actually contains all the data from all other layers too (see screenshots). How can I have the code explicitly reference a single layer in my map?
prj = arcpy.mp.ArcGISProject(prjPath)
m = prj.listMaps('Map')[0]
lyr_zone = m.listLayers()
for l in lyr_zone:
if 'zone' in l.name:
print (l.name)
service = l.name
# Local paths to create temporary content
outdir = r"C:\\10000_VGF\VGF soil zones\Temp"
sddraft_filename = os.path.join(outdir, service + ".sddraft")
sddraft = m.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", service)
sddraft.summary = "Soil zones created using Veris technology for VGF"
sddraft.tags = "soil, zones"
# Create Service Definition Draft file
print("Creating SD file")
sddraft.exportToSDDraft(sddraft_filename)
# Stage Service
print("Creating Stage Service file")
sd_filename = os.path.join(outdir, service + ".sd")
arcpy.StageService_server(sddraft_filename, sd_filename)
# Share to portal
print("Uploading Service Definition...")
arcpy.UploadServiceDefinition_server(sd_filename, "My Hosted Services", in_folder_type = "Existing", in_folder = "Soils", in_organization = "SHARE_ORGANIZATION")
print("Successfully Uploaded service.")

