Hello, I work with ArcGIS API for Python on a service hosted in AGOL. I would like to update a field based on another field. I have tried many times, I do not understand how to do it. The example in the API is based on the update between two documents.
Someone to help me ?
Thank you
Solved! Go to Solution.
Hope the following code snippet gives you some clue:
from arcgis.gis import GIS
from arcgis.features import FeatureSet, Feature
gis = GIS(url="",username="",password="")
fs=gis.content.get(itemId)
# assume the first layer is the layer you want to update
fl=fs.layers[0]
# set return_geometry false will save you time and data
features=fl.query(where=sql_where,out_fields='OBJECTID,FieldName'
,return_geometry=False)
for feature in features:
# Calculate the new value and assign it to the field in the current record
feature.set_value('FieldName',NewValue)
# update the features in AGOL
results = fl.edit_features(updates=features)
Hope the following code snippet gives you some clue:
from arcgis.gis import GIS
from arcgis.features import FeatureSet, Feature
gis = GIS(url="",username="",password="")
fs=gis.content.get(itemId)
# assume the first layer is the layer you want to update
fl=fs.layers[0]
# set return_geometry false will save you time and data
features=fl.query(where=sql_where,out_fields='OBJECTID,FieldName'
,return_geometry=False)
for feature in features:
# Calculate the new value and assign it to the field in the current record
feature.set_value('FieldName',NewValue)
# update the features in AGOL
results = fl.edit_features(updates=features)
Thank you Simo Xu
Have a good day
You are welcome, thank you
Hello Simo,
Maybe you can help me on this point. I'm still working with this web service, hosted under AGOL and with ArcGIS API for Python.
On a field of type 'date', I would like to empty the field of its contents.
However when I try, here is the result 1/1/1900 11h05
Do you have an idea ?
Thank you
I don't know how you did it, but could you test whether or not the following code works?
feature.set_value('DateFieldName',None)
With your proposal it does not change. The content of the field remains the same.
Before asking for your help I tried this:
feature.set_value('DateFieldName',"")
RESULT >> 1/1/1900 11:05 AM
The field settings have this parameter.
Allow null values is set to Yes
You are right.
I tried SQL in Map Viewer, it didn't work either.
I have to manually do it in AGOL Map Viewer using Arcade expression to set the Date column to NULL. But I am not sure this is what you want.
.
Very nicely done. I wish the Esri help documentation on this topic was this straightforward and to the point.