Type Error with is_service_name_available

169
2
Jump to solution
12-01-2021 12:45 PM
GIS_utahDEM
Occasional Contributor

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")

 

 

0 Kudos
1 Solution

Accepted Solutions
AtmaMani
Esri Contributor

Please try it like this:

gis.content.is_service_name_available(....)
# or like this:
cm = ContentManager(<gis_instance>)
cm.is_service_name_available(..)

Long answer:

The is_service_name_available() method is an instance method (not static), so you need to call it on an instance. We prefer the first pattern in the example above as it is easier to read

View solution in original post

0 Kudos
2 Replies
AtmaMani
Esri Contributor

Please try it like this:

gis.content.is_service_name_available(....)
# or like this:
cm = ContentManager(<gis_instance>)
cm.is_service_name_available(..)

Long answer:

The is_service_name_available() method is an instance method (not static), so you need to call it on an instance. We prefer the first pattern in the example above as it is easier to read

0 Kudos
GIS_utahDEM
Occasional Contributor

Thank you! That worked

0 Kudos