Select to view content in your preferred language

AGOL Notebook

09-10-2023 08:28 AM
Labels (3)
New Contributor II


I am trying to run a calculate field notebook on AGOL (the feature layer is a table). I've run the notebook code in ArcPro and it works, but having the below errors returning when trying to use the notebook online: 

ExecuteError                              Traceback (most recent call last)
/tmp/ipykernel_284/ in <cell line: 2>()
      1 arcpy.ImportToolbox
----> 2 arcpy.CalculateField_management(      3     in_table=EPD_Actions_and_Checklist_Id,
      4     field="DaysOverdue",
      5     expression="""var completed = $feature.DateCompleted

/opt/conda/lib/python3.9/site-packages/arcpy/ in CalculateField(in_table, field, expression, expression_type, code_block, field_type, enforce_domains)
   6185         return retval
   6186     except Exception as e:
-> 6187         raise e
   6189 @gptooldoc('CalculateFields_management', None)

/opt/conda/lib/python3.9/site-packages/arcpy/ in CalculateField(in_table, field, expression, expression_type, code_block, field_type, enforce_domains)
   6182     from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
   6183     try:
-> 6184         retval = convertArcObjectToPythonObject(gp.CalculateField_management(*gp_fixargs((in_table, field, expression, expression_type, code_block, field_type, enforce_domains), True)))
   6185         return retval
   6186     except Exception as e:

/opt/conda/lib/python3.9/site-packages/arcpy/geoprocessing/ in <lambda>(*args)
    510         val = getattr(self._gp, attr)
    511         if callable(val):
--> 512             return lambda *args: val(*gp_fixargs(args, True))
    513         else:
    514             return convertArcObjectToPythonObject(val)

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Table: Dataset 7bb00f43e7bc49f4aa4e3e50b46de6cc does not exist or is not supported
Failed to execute (CalculateField).

I know you can calculate field using Arcade straight into the table, however, I need this (and others) to run automatically. 

Below is the code being used

from arcgis.gis import GIS
import arcpy
gis = GIS("home")

expression="""var completed = $feature.DateCompleted
var startDate = Date($feature.TargetDate)
var endDate = Date(Now())
var daysoverdue = DateDiff(endDate, startDate, 'days')

if ($feature.Status == "Completed"){
return 0;
} else if (isempty(startDate)){
return 0;
} else if (isempty(completed)){
return daysoverdue;

Any suggestions, that would be great.

If there is also a way in which I don't have to use an advanced notebook, that would also be great

I have enabled editing on the feature service layer and am using the advanced notebook.


0 Kudos
1 Reply
MVP Regular Contributor

If you want to avoid using an advanced notebook, scrap the Calculate Field tool altogether.  You can use the ArcGIS API for Python to do the following:

  • Open your feature layer
  • Query the features you need (using the FeatureLayer.query method)
  • Create a list of updated features (Python dictionaries) using Python date calculations
  • Push the updates to the feature layer (using the FeatureLayer.edit_features method)

Have a look at the arcgis.features module to get started.