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."]}}
Hello @AaronSchuck ,
I am trying to do the same thing. Did you find another way to work on this?
Thanks
Not yet, I have been working with ESRI tech support but they don't seem to know the answer either!
Hi Team,
did anyone find a way to update contingent values, i have also tried the same with updateDefinition and got the below error
I really wish we could get a response from ESRI on this. I am using the Notebook from the Tree Solution and I am getting the same error when trying to update Contingent values in one of my own services. I have checked all my output syntax in comparison to the working ESRI example and can find no differences. Format is identical.
This is my error:
Exception: Unable to add feature service layer definition.
Invalid definition for System.Collections.Generic.List`1[ESRI.ArcGIS.SDS.FieldGroup]
Failed to add items to the Contingent Values Definition: ", { "Errors": ["Error - Unable to update layer definition. (Method name: UpdateCVDefinitionAndCode), "]}
(Error Code: 400)
Hello,
Can you post the link for that Notebook you were trying to use? I am curious to see if it would work for us as we are stuck looking for a solution on updating our contingent values in AGO. We really don't want to download the layer and make the updates locally then re-publish every time we need to make an update.
Thanks!
Hi Matt,
I did get it to work. Off for the eclipse but will post my findings tomorrow.
Thank you so much!
Good morning @MatthewBarr6 I have attached two version of my notebook.
One is for updating a single feature services. The second will loop through layers if you have multiple layers in your hosted service. The trick that I found is that you need to import via CSV to your table that will be used for the list of values. I have included a FGDB of the tables and a csv that I used for importing.
I fought with list errors for a while until I realized that any cells that are blank need to be nulls or you will get an error.
You are the best, I am downloading them now and going to give it a shot! Will let you know if it works!