Select to view content in your preferred language

How to use the Update Definition operation on a hosted layer view in AGOL

3351
13
Jump to solution
05-17-2018 12:11 PM
Trippetoe
Occasional Contributor III

I am trying to use the Update Definition operation on a hosted feature layer view through the Admin view of the REST endpoint of the feature service.  The change i am trying to make is setting some default values in the 'templates' element.  However, regardless of the changes i try to make to the definition, i am getting the following error message:

Invalid definition for 'DefinitionQuery'.
Invalid definition for System.String

Even for the simplest change of setting "lastEditDate" : " ", I get the error message.  I am the owner of the view.

The definition query (as generated by AGOL when creating the view) looks like this:

{

...

"viewDefinitionQuery" : "(IsActive = 'Yes') AND (CaseType = 'Report') AND (ReportStatus = 'Received')",
"definitionQuery" : "(IsActive = 'Yes') AND (CaseType = 'Report') AND (ReportStatus = 'Received')"

...

}

Any thoughts on what's going on?

1 Solution

Accepted Solutions
JohnMarino
New Contributor III

The issue appears to be with having a Definition Query applied to the Feature Layer View when attempting to update its 'definition.'

In case anyone else encounters this error message, here is a workaround that was successful for me:

  1. remove all definition queries for the feature layer view [edit: be sure to save your definition queries for later retrieval, or at least remember what they are]
  2. update the definition of the feature layer view
  3. re-enable any definition queries previously removed in step 1

View solution in original post

13 Replies
Trippetoe
Occasional Contributor III

Esri Tech Support has verified that this is a bug in AGOL.  The bug number is #BUG-000114175

0 Kudos
larrycamp
New Contributor III

Is the bug the whole method of using Update Layer Definition?

Or is the bug related to this poster's Def Qry only?

I'm running into similar problem trying to update a field to nullable = false.

0 Kudos
JohnMarino
New Contributor III

The issue appears to be with having a Definition Query applied to the Feature Layer View when attempting to update its 'definition.'

In case anyone else encounters this error message, here is a workaround that was successful for me:

  1. remove all definition queries for the feature layer view [edit: be sure to save your definition queries for later retrieval, or at least remember what they are]
  2. update the definition of the feature layer view
  3. re-enable any definition queries previously removed in step 1
by Anonymous User
Not applicable

I had the same exact issue as described by Tom Rippetoe‌ and this 3-step process worked like a charm. I hope there's a bug fix coming soon on this or at least a more useful error. Anyway, in my opinion this should replace the current Correct Answer as it provides an actual workaround rather than a link to a promise of fix. Thank you for sharing, John Marino!

Trippetoe
Occasional Contributor III

Works for me. i updated the correct answer.

MichaelVolz
Esteemed Contributor

Thanks for sharing that information John.  That is the best part of GeoNet!!!!

fklotz
by
Occasional Contributor

The latest BUG on this is marked as "By Design".  The fix is quite easy to implement, but it is annoying that Esri's error messaging is not better or that the updateDefinition doesn't take care of these things by itself.

From the bug page: 

Bug ID Number BUG-000155365
SubmittedJanuary 25, 2023
Last ModifiedOctober 12, 2023
Applies toArcGIS Online
Version foundNovember 2022
Operating SystemWindows OS
Operating System Version11.0 64 bit
StatusAs Designed 
 

Additional Information

When updating a layer definition from REST, it is recommended to only include the part of the definition that is being updated. Including the entire definition may cause the update definition to fail. The "definitionQuery" cannot be updated by updating the layer definition. However, you can update the "viewDefinitionQuery" without including the rest of the layer definition including the "definitionQuery".

End of bug page content.

What this means is when you update the definition query, you only need to include the elements you want to update.  For example, if the bottom of my layer's definition shows:

 

  "maxRecordCount" : 1000, 
  "standardMaxRecordCount" : 32000, 
  "tileMaxRecordCount" : 8000, 
  "maxRecordCountFactor" : 1, 
  "capabilities" : "Query", 
  "viewDefinitionQuery" : "CreationDate > timestamp '2023-01-01 05:59:59'", 
  "definitionQuery" : "CreationDate > timestamp '2023-01-01 05:59:59'", 
  "exceedsLimitFactor" : 1, 
  "layerOverrides" : [
    "allowGeometryUpdates", 
    "capabilities", 
    "ownershipBasedAccessControlForFeatures"
  ]
}

 

and I want to modify the maxRecordCount and the view's definition query, I would submit the following to the updateDefinition end point:

 

{
  "maxRecordCount" : 5000, 
  "viewDefinitionQuery" : "CreationDate > timestamp '2024-01-01 05:59:59'"
}

 

Looking at the layer definition afterwards, we can see that those elements have been updated:

 

"maxRecordCount" : 5000, 
  "standardMaxRecordCount" : 32000, 
  "tileMaxRecordCount" : 8000, 
  "maxRecordCountFactor" : 1, 
  "capabilities" : "Query", 
  "viewDefinitionQuery" : "CreationDate > timestamp '2024-01-01 05:59:59'", 
  "definitionQuery" : "CreationDate > timestamp '2024-01-01 05:59:59'", 
  "exceedsLimitFactor" : 1, 
  "layerOverrides" : [
    "allowGeometryUpdates", 
    "capabilities", 
    "ownershipBasedAccessControlForFeatures"
  ]
}

 

Farley
0 Kudos
RobBurke
New Contributor III

How do you carry out the first step?  "remove all definition queries for the feature layer view"

 

Robert Burke
fklotz
by
Occasional Contributor

Steps that worked for me:

  1. Navigate to the ArcGIS REST Services Directory page for the specific layer within your Hosted Feature Layer
  2. Use the "deleteFromDefinition" REST end point, passing it both the "viewDefinitionQuery" and the "definitionQuery" from the layer in your view. e.g., 

 

{
"viewDefinitionQuery" : "(field1 = 12345) AND (field_name_two = 'bobsyeruncle')",
"definitionQuery" : "(field1 = 12345) AND (field_name_two = 'bobsyeruncle')"
}​

 

  • After step 2 is complete, use the "addToDefinition" REST end point, passing it ONLY the "viewDefinitionQuery", ESRI will add the "definitionQuery" for you automatically. If you try to pass both, you will get the "Invalid definition for System.String" error.

 

{
"viewDefinitionQuery" : "(field1 = 98765) AND (field_name_two = 'slurm is tasty')"
}​

 

Farley