I’m trying to use addToDefinition in arcpy to create a view layer with a filter.
At first, I tried something like this, using Add to Definition (Feature Service) | ArcGIS REST APIs | Esri Developer as a reference:
"filter": "<filter>
But this generated an error: “A database error has occurred.”
Then, by checking the server logs, I noticed the error “not a JSON object”, so I understood that I needed to pass a dictionary instead.
So I tried something along the lines of:
"filter": {
"where": "xxx",
"field_name": "yyy"
}
and also:
"viewDefinitionQuery": {
"where": "field_name = 'some_value'"
}
This time I didn’t get any errors, and the view was created successfully — but the filter was not applied.
My question is:
What is the correct way to create a view layer with addToDefinition in arcpy and apply a filter at the same time?
Any guidance or working example would be greatly appreciated.