<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Why is my definition query having no effect? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/why-is-my-definition-query-having-no-effect/m-p/1218209#M7835</link>
    <description>&lt;P&gt;If the goal here is to apply a filter to a layer in a webmap in ArcGIS Online use the following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis import GIS
from arcgis.mapping import WebMap

## connect to AGOL
agol = GIS("home")

## get the WebMap you want to update
wm_item = agol.content.get("WEBMAP_ITEM_ID")

## create WebMap object
webmap = WebMap(wm_item)

## get the layer of interest
lyr = webmap.get_layer(title="LAYER_NAME")

## the query to apply
def_qry = "GUIDId = '{0}'".format(RequestedGUIDId)

## set the filter definition
lyr.layerDefinition.definitionExpression = def_qry

## update the webmap
wm.update()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Oct 2022 10:31:19 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2022-10-03T10:31:19Z</dc:date>
    <item>
      <title>Why is my definition query having no effect?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/why-is-my-definition-query-having-no-effect/m-p/1217734#M7829</link>
      <description>&lt;P&gt;I'm trying to narrow down a layer using the lyr.definitionQuery = ... method, as below:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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 + "'"&lt;/LI-CODE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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!).&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 06:04:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/why-is-my-definition-query-having-no-effect/m-p/1217734#M7829</guid>
      <dc:creator>MichaelBell</dc:creator>
      <dc:date>2022-09-30T06:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my definition query having no effect?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/why-is-my-definition-query-having-no-effect/m-p/1218209#M7835</link>
      <description>&lt;P&gt;If the goal here is to apply a filter to a layer in a webmap in ArcGIS Online use the following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis import GIS
from arcgis.mapping import WebMap

## connect to AGOL
agol = GIS("home")

## get the WebMap you want to update
wm_item = agol.content.get("WEBMAP_ITEM_ID")

## create WebMap object
webmap = WebMap(wm_item)

## get the layer of interest
lyr = webmap.get_layer(title="LAYER_NAME")

## the query to apply
def_qry = "GUIDId = '{0}'".format(RequestedGUIDId)

## set the filter definition
lyr.layerDefinition.definitionExpression = def_qry

## update the webmap
wm.update()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 10:31:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/why-is-my-definition-query-having-no-effect/m-p/1218209#M7835</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2022-10-03T10:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my definition query having no effect?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/why-is-my-definition-query-having-no-effect/m-p/1218507#M7844</link>
      <description>&lt;P&gt;That's definitely some useful code. However, my code *was* working, but my code hadn't been put together well. I was trying to address a layer which didn't exist because I hadn't given it a title in the json I'm putting the webmap together with.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 03:56:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/why-is-my-definition-query-having-no-effect/m-p/1218507#M7844</guid>
      <dc:creator>MichaelBell</dc:creator>
      <dc:date>2022-10-04T03:56:37Z</dc:date>
    </item>
  </channel>
</rss>

