Hi guys,
I'm trying to calculate and update a field in a feature layer in ArcGIS Online on a daily basis (using ArcGIS Arcade). I can do it manually by running the script on the field. But, I'd like to automate this.
I wrote the following python script (which works fine from ArcGIS pro installed on my desktop machine).
# Code to update a field in a Feature Layer using Arcade
import arcpy
# Feature service URL of layer to update
layerToUpdate = "https://<featureservice-url>/<layerId>"
fieldToUpdate = "fieldName"
arcadeExpression = "'Hello World'"
# Process: Calculate Field
arcpy.management.CalculateField(in_table = layerToUpdate, field = fieldToUpdate, expression = arcadeExpression, expression_type = "ARCADE", code_block = "")
But, I haven't been able to get this to work using ArcGIS Online Notebooks (Advanced runtime).
I keep getting the following error.
ExecuteError: ERROR 160228: The user does not have permission to execute the operation. Failed to execute (CalculateField).
Any help would is greatly appreciated 🙂
Solved! Go to Solution.
Hi @GFernando !
Could you try signing in with arcpy.SignInToPortal(<portalurl>, <username>, <password>) prior to running your cells? This is a common hiccup people have when running arcpy commands since this is not required in Pro. We are working to integrate this better into ArcGIS Online.
You can call arcpy.GetActivePortalURL() to get your current env url. Let me know if that solves things for you.
Josh
Hi @GFernando
It is a bit unclear for me why do you want to run this from a Notebook. If your goal is to run this script daily then you can create a batch file that call Python and run the script, then add the file to a schedule task usign task Scheduler, that's if you are using Windows. Not sure about the alternatives for other OS.
Regards
Ihab
Hi @IhabHassan, thanks so much for the reply and this was my first suggestion too.
But unfortunately, Task Scheduler is blocked in our org 😞
there are some free alternatives, but I am not sure if you would be able to run/install any. If you can't install one, then you might need to build your own using .Net framework.
https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskscheduler?view=net-5.0
Thanks @IhabHassan for looking into it further. Unfortunately, this approach wouldn’t work either - as our org wouldn’t allow any customisation on our machines 😞
Ideally, it would be great if I can get the proposed script to work on ArcGIS Online Notebooks. Otherwise, will need to replicate the script in Python (and run it in ArcGIS Online Notebooks).
Thanks
Hi @GFernando !
Could you try signing in with arcpy.SignInToPortal(<portalurl>, <username>, <password>) prior to running your cells? This is a common hiccup people have when running arcpy commands since this is not required in Pro. We are working to integrate this better into ArcGIS Online.
You can call arcpy.GetActivePortalURL() to get your current env url. Let me know if that solves things for you.
Josh
Thanks so much @Anonymous User - that seems to execute the code.
But, now I get the following error.
The kernel appears to have died. It will restart automatically.
Hmmm - how large is the dataset you're running it on? did you run it on a new container? Try deleting your container (under the 'Manage Notebooks' button on the Notebook homepage, click the trash can next to the relevant container) and running again. It might be that the kernel is crashing due to RAM usage or something of that sort from the previous attempts.
If it consistently crashes please contact support and we can try to get it sorted. You can also try filtering the data (i.e. the last 50 rows) and see if that makes a difference - if it does, it's likely data related.
Hi @Anonymous User, it's a small dataset (10 features) running on a new container. And I'm currently only trying to write "Hello World" as per the code snippet above.
Yep, will get in touch with Support.
Thanks so much,
Gee
Hi @Anonymous User,
This works now 🙂
It's great being able to schedule Arcade field calculations using AGOL Notebooks 😉