I'm trying to determine if a definition query is applied to a layer in a feature service referencing one of our enterprise geodatabases. Does anyone know how to grab the applied definition query via the REST or Python API's?
Here's where I've looked so far. The REST API response(documentation link) for a service layer doesn't contain this information.
I am able to grab the service manifest via REST (documentation) and inspect the JSON. It contains the connection properties for source geodatabase, and the name of the feature class used by each service layer. However but it doesn't contain any information about the definition query either. The manifest does show a serverpath for the location of the service's .MSD file on the server's disk.
Therefore I'm guessing this definition query information only lives within the MSD file itself. My server admin was able to grab the msd file for me off disk and I verified the definition query is buried in there. I guess I could write a script to grab the file and parse it, but figured this would be somewhere in the server admin interface or API's.
If the REST API does not have a method to return a feature service's definition query it should be added. I can see this being useful.
Bernie.
You can't see it in the REST directory page, but if you flip over to the JSON side, you can see this down at the bottom:
"viewDefinitionQuery": "GRID_ID NOT IN ('A-1','A-10','A-11')",
"definitionQuery": "GRID_ID NOT IN ('A-1','A-10','A-11')"
Similarly, you can use the Python API to pull these out.
fl = gis.content.get('itemid').layers[0]
fl.manager.properties['viewDefinitionQuery']
If one exists, those lines will return the SQL definition.
Thanks Josh, I'm not that getting those elements when I navigate to the json for my layer. I'm looking at this URL logged in with an admin account: https://<myArcGISServerUrl>/server/rest/services/<MyServiceName>/MapServer/0?f=pjson
my portal and arcgis server are 10.9.1
Was your example from a hosted feature service by chance? I found this article that walks through how to navigate to this spot in the json, but it's for a hosted feature service.
In my scenario I am trying to find the definition query for a layer in a service referencing an enterprise geodatabase. The service creation process would be something like 1)a GIS Analyst opens pro and adds a feature class from the geodatabase to the map, 2) adds a definition query to the layer, 3) then publishes to Portal or Server as reference with features access. Now 6 months later someone asks me the admin "why doesn't this feature layer have all the features in it from the original feature class?
-Andrew
I'll add my vote for this feature to come over to Portal and on-prem map services. One of our largest customers needs to use a definition query to filter what features are shown/query-able through a sync replica (using Maps SDK). Most straightforward way to is to include two layers in their map service, each with different definition queries. Seems the definition query is unsupported in two ways. First, the definition query isn't respected when the replica is generated, producing two layers that contain all the results. Second, the definition query isn't in the meta-data (as mentioned above), making it hard to work around the problem. For, we could use the Maps SDK to take the definition query from the service and push it into the FeatureLayer built from a replica table. Any timeline for this feature?
This would be a hugely helpful feature. We have many services and often they are reading from the same dataset with different queries and so being able to refer back to the original query used would be invaluable, instead of having to try and recreate them from memory.
@AndrewRudin1 did you ever get around to scripting this? How would you even go about accessing the MSD and parsing it? I managed to extract the contained json from the MSD file but only with some fiddling around, I am not exactly sure how I would approach this programmatically.