Good afternoon
I am trying to update the definition query of two layers using arcpy python
For testing purposes, I am resetting the query, but nothing happens
from arcgis.gis import GIS
from arcgis.mapping import WebMap
gis = GIS("Pro")
webmap_item = gis.content.get("-..webmapid....")
web_map = WebMap(webmap_item)
# Get all layers from the web map
for layer in web_map.layers:
print(layer.title)
if layer.title == "first layer":
layer.definitionQuery = None
if layer.title == "second layer":
layer.definitionQuery = None
webmap_item.update() ==>> It looks like this update does not work
It's been a while but I think the Webmap doesn't contain feature layers where you can update line that. It's a big block of JSON - could be wrong however . I'd try something like:
for layer in web_map.definition["operationalLayers"]:
if layer["title"] in ["first layer", "second layer"]:
if "layerDefinition" in layer:
layer["layerDefinition"]["definitionExpression"] = "<insert definition query>"
webmap_item.update({"text": json.dumps(web_map.definition)})