I am having issues using ContentManager.is_service_name_available(). I am using it within a for loop to create view layers to check whether the view layer has already been created (code below). I am getting errors that I don't have a "self" argument, even though I'm pretty sure I do (screenshot of error below). If anyone has insight in how to fix this, or another method of checking whether a layer has already been created, let me know! Thanks in advance.
# Loop through the regional division to create the views
for index, county in enumerate(counties_munis):
county_name = counties_munis.features[index].attributes['NAME']
print(county_name)
view_name = 'UCIP_' + "_" + county_name + "_View"
print(view_name)
# Get the geometry for the regions
view_geom = counties_munis.features[index].geometry.get('rings')
name_avail = ContentManager.is_service_name_available(service_name = view_name,service_type = "featureService")
# Check if view exists
if name_avail == True:
new_view = ucip_locs_flc.manager.create_view(name=view_name)
# Search for newly created View
view_search = my_agol.content.search(view_name)[0]
view_flc = FeatureLayerCollection.fromitem(view_search)
service_layer = view_flc.layers[0]
layerTags = [county_name,"UCIP","View Layer"]
# Populate the update_dict with the geometry and the spatial reference
update_dict = {"tags":layerTags,"viewLayerDefinition":{"filter":
{"operator":"esriSpatialRelContains","value":
{"geometryType":"esriGeometryPolygon","geometry":
{"rings": view_geom,
"spatialReference":spat_ref}}}}}
# Update the definition to include the Area of Interest
service_layer.manager.update_definition(update_dict)
print("Added ",view_name)
else:
print(view_name," Exists")