I'm trying to narrow down a layer using the lyr.definitionQuery = ... method, as below:
result = arcpy.mp.ConvertWebMapToArcGISProject(data, templateFull)
aprx = result.ArcGISProject
#get the map, layer, apply the definition query
m = aprx.listMaps()[0]
lyr = m.listLayers("MyLayer")[0]
lyr.definitionQuery = "GUIDId = '" + RequestedGUIDId + "'"Now, this works fine if I do it using my current project on my computer, with everything loaded locally (so I don't have to bother with the ConvertWebMapToArcGISProject). However, we're trying to implement this online, so we have to get a json containing the layers we need and convert it to a project in the code.
Now, for some reason, the lyr.definitionQuery line is not working - or more rather, it's having no effect. No matter what, it always returns the same number of features, which is odd (as my layer contains about 20,000 features - yet it always returns 151, even if I enter different values, or even values that don't exist!).
The layer does support definition queries (I've tested that), and it definitely recalls the definition query (I've given it a delay after the definition query is set, and checked it by outputting). It's getting set, but for some reason the layer isn't paying any attention to it.