Is it possible to update contingent values on an AGOL hosted feature service?

708
10
07-19-2023 02:52 PM
AaronSchuck
New Contributor III

I have a hosted feature service on ArcGIS Online with some contingent values.  I have been trying to change the contingent values by updating the "values:[]" to different numbers, but I must be getting the syntax wrong as I can't push the update through.

 

 

 

import arcpy
from arcgis.gis import GIS
import requests
import json
import arcpy
gis = GIS("pro", use_gen_token=True)
currentUser = gis.users.me
token = gis._con.token

params = {"f":"json", "token": token, "updateDefinition":{"contingentValuesDefinitions":[{"layerID":0,"layerName":"Testing_Round3","geometryType":"esriGeometryPoint","hasSubType":"false","fieldGroups":[{"name":"BestFieldGroup","restrictive":"true","fields":[{"id":0,"name":"FieldOne","fieldType":"esriFieldTypeString"},{"id":1,"name":"FieldTwo","fieldType":"esriFieldTypeString"},{"id":2,"name":"FieldThree","fieldType":"esriFieldTypeString"}],"domains":{"FieldOne":"FieldOne","FieldTwo":"FieldTwo","FieldThree":"FieldThree"},"contingentValues":[{"id":1,"types":[3,3,3],"values":[0,1,2]},{"id":2,"types":[3,3,3],"values":[1,2,0]},{"id":3,"types":[3,3,3],"values":[2,0,1]}]}]}]}}
urlpost = r'https://services8.arcgis.com/BD3gY4Sn5bdx9tEl/arcgis/rest/admin/services/Test_CVs_Round3_gdb/FeatureServer/updateDefinition?token={}'.format(token)
r = requests.post(urlpost, data=params)
rJson = r.json()
print(rJson)

 

 

 

Executing the code in Pro gets a return of :

{'error': {'code': 400, 'message': 'Unable to update feature service definition.', 'details': ["Invalid definition for ''.", "Unexpected character encountered while parsing value: c. Path '', line 0, position 0."]}}

10 Replies
MatthewBarr6
New Contributor II

I was able to use the code from the notebook to write a local script and get a couple questions I needed answered that I couldn't find online.  Everything is running smoothly on my end, and we are able to easily update our contingent values now without having to download the layer!  Thank you so much @CraigCheeseman  for the quick reply, you just saved me a ton of time and headache! 

0 Kudos