I have a feature class that I maintain in a geodatabase that has editor tracking enabled. It has the standard fields: created_user, created_date, last_edited_user and last_edited_date. I'm using the python functions in arcpy.mp to create the SD draft and to stage the definition file. Then using the ArcGIS API for Python to update and publish the SD file in AGOL.
When I publish my map, all values in my editor tracking fields get overwritten with the date/time the script runs and the username that I use to login to AGOL. If I choose to make those fields not visible in my Pro project, then no data appears in my updated service. This happens despite having editing capabilities disabled.
Is there a way to prevent this overwrite from happening? I would like the tracking information to reflect what I have in my geodatabase.
Best,
Leon
Solved! Go to Solution.
Hi Leon,
You can preserve editor tracking when making the publish call to the rest API and adding the property: preserveEditUsersAndTimestamps example:{"editorTrackingInfo":{"enableEditorTracking":true,"preserveEditUsersAndTimeStamps":true}}
This documentation will help: ArcGIS REST API
I'm not as familiar with the ArcGIS Python API, but it looks like you should be able to add the above information as a publish)parameter when using publish: arcgis.gis module — arcgis 1.0 documentation
Here is a link to a similar script that maintains editor tracking when publishing from a FGDB by making direct REST API calls: http://cloudygis.maps.arcgis.com/home/item.html?id=2d7027b148e24005916e55ab2cb74b50
Feel free to share your code if you have questions on how to implement this.
-Kelly
Hi Leon,
You can preserve editor tracking when making the publish call to the rest API and adding the property: preserveEditUsersAndTimestamps example:{"editorTrackingInfo":{"enableEditorTracking":true,"preserveEditUsersAndTimeStamps":true}}
This documentation will help: ArcGIS REST API
I'm not as familiar with the ArcGIS Python API, but it looks like you should be able to add the above information as a publish)parameter when using publish: arcgis.gis module — arcgis 1.0 documentation
Here is a link to a similar script that maintains editor tracking when publishing from a FGDB by making direct REST API calls: http://cloudygis.maps.arcgis.com/home/item.html?id=2d7027b148e24005916e55ab2cb74b50
Feel free to share your code if you have questions on how to implement this.
-Kelly
Hi Kelly,
That's exactly what I was looking for. Thank you for pointing me in the right direction!
- Leon
####Python snippet
gis = GIS(agol_url, agol_user, agol_pass)
#Find SD file, then update or add, then publish
sd_items = gis.content.search("id:" + sd_itemid +" AND owner:" + agol_user, item_type="Service Definition")
#Parameters for editor tracking
pub_params = {"editorTrackingInfo" : {"enableEditorTracking":'true', "preserveEditUsersAndTimestamps":'true'}}
if sd_items:
sd_item = sd_items[0]
updatesuccess = sd_item.update({},final_sd)
if updatesuccess:
sd_item.publish(publish_parameters=pub_params, overwrite="true")
Excellent!
Thanks for posting the snippet too!
First I want to thank you all for the snippet of code that you posted. This helped me get on the right track. I did want to add my snippet of code that essentially builds on the one that was posted by Leon.
I was able to use Jupyter Notebooks to test my functionality. Note the following:
1) I had ArcGIS Pro running in the background and I was also connected to my ArcGIS Online portal (enterprise account).
2) If you use the "pro" keyword when instantiating the GIS module, it will grab the credentials ... and token from the logged in user from Pro
3) I used the "get" option instead of "search" since I had access to the exact service ID - this returns only one item instead of a list of items (less code).
4) This script only works when your ArcGIS Pro is logged in as the OWNER
5) It took it a little bit to run ... so be patient because I did not have an indication of when it was done. Once it was done, I was able to view the data (table) and see that the create and update users were preserved
from arcgis.gis import GIS
gis = GIS("pro")
#Find SD file, then update or add, then publish
sd_item = gis.content.get("4dd54080b9af4b5bae9b6fa020f3XXXXX")
#Parameters for editor tracking
pub_params = {"editorTrackingInfo" : {"enableEditorTracking":'true', "preserveEditUsersAndTimestamps":'true'}}
sd_item.publish(publish_parameters=pub_params, overwrite="true")
Any suggestions on how i can do the same thing - preserve creator/editor information - when publishing to AGOL via ArcMap/ArcPro? I have a similar scenario where we are regularly publishing data to AGOL from our SDE database. Instead of using python like the original poster, we are using ArcMap.
I was able to get a service definition created and published to AGOL using this approach, but there are a few issues I am dealing with.
I certainly appreciate that this work around exists, but unless I can address the issues above, I'm still left wanting for a simplistic and full-picture resolution.
Hi Christopher,
I'd suggest getting in contact with Tech Support. It looks like there could be some issues with this specific dataset and you are using a work around for an issues with relationships, so it's probably best to get an analyst to work with you and the data.
What version of ArcMap and ArcGIS Pro are you using?
-Kelly
Hi Kelly,
I was able to get it working with the following workflow.
This was certainly not an intuitive process, but I was forced to figure it out due to a project I was working on. Hope this helps others.
Thanks,
Chris B.
Hi Tom,
I don't believe this functionality is available through ArcMap. I'd suggest using the Python for this.
-Kelly