Select to view content in your preferred language

How to update a feature layer from related table daily - Arcade in Notebook?

603
2
01-23-2024 12:03 PM
NoahWasserman
New Contributor III

I have a point layer "sites" and a related table "inspections" running for Field Maps data collection and a Dashboard visualization of what's going on (based on this workflow). In the webmap popup I can use Arcade to find the most recent inspection (or no inspection) in the related table based on each site point, etc. Now I need to populate fields in the parent point "sites" layer with a daily update for "next inspection" (a straightforward calculation based on data in "sites" attribute table), "last inspection" (a query of the related records for each site), and a third field where an arcade script decides if an inspection is due. I can calculate these manually in the Data view at ArcGIS.com with arcade.  Is there a way to automate this to run daily via ArcGIS.com or ArcPro desktop? I can't figure out how to reference, sort, select most recent inspection, etc from the related table data in model builder for Pro desktop (to schedule a task) or how to use Calculate/Notebooks with Arcade to schedule a task online.

2 Replies
marksm_macomb
Occasional Contributor

I just figured out a workflow for this recently that's been running pretty well for the past couple months now, but unfortunately there is not a way to schedule run an Arcade script (I much prefer Arcade as well, and looked for an Arcade solution for a while before giving up) so this is a job for Python. For the "bones", I referenced this blog post which got me really close to a working script. I tweaked it with some trial and error and tried to document that in this comment on the blog

This may give you a starting point, but you will likely have some more customized code for your specific calculations.

0 Kudos
ChristopherCounsell
MVP Regular Contributor

You can run this as a scheduled ArcGIS Notebooks task in ArcGIS Online. Better than ArcGIS Pro as it's always on.

I would recommend:

  1. Adding a field to your related table in Field Maps to flag if the inspection has been processed. E.g. "Processed", default = 'no'. This lets you identify the inspection records that have not been processed.
  2. Create an ArcGIS Notebook in ArcGIS Online. It should:
    1. Identify the records that have not been processed (use above field). Query the layer.
    2. Create a for loop to go through each feature from the query and apply an edit to the parent feature using the parentglobalid and the query attributes result.
    3. If successful, mark the inspection record as processed

You will need to use Python but it's similar enough to Arcade and the above workflow is relatively lightweight. Make sure to test your python script on test data and use try/except + print() to help with errors and troubleshooting. 

https://doc.arcgis.com/en/arcgis-online/create-maps/prepare-a-notebook-for-automated-execution.htm