Publishing to AGOL overwrites editor tracking data

7157
17
Jump to solution
01-04-2017 11:30 AM
LeonS
by
Occasional Contributor II

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

1 Solution

Accepted Solutions
KellyGerrow
Esri Frequent Contributor

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

View solution in original post

17 Replies
KellyGerrow
Esri Frequent Contributor

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

LeonS
by
Occasional Contributor II

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")

KellyGerrow
Esri Frequent Contributor

Excellent!

Thanks for posting the snippet too!

DianaBenedict
Occasional Contributor III

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")

Trippetoe
Occasional Contributor III

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.

0 Kudos
ChrisBlinn1
Occasional Contributor

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.

  1. Many issues around relationships. 
    • The relationships in my data are not all created.  Only the Parent relationships show up in the definition for each, but when I go to the Child element definition, it does not have the relationship referenced back to the Parent.
    • The relationships have no name value, this breaks many applications trying to read the relationships from the definition (i.e. Survey123).
  2. Script hates an SD from ArcMap.
    • This issue stems from another existing issue where publishing a service from ArcGIS Pro drops domains from data.  The only valid workaround is the publish from ArcMap - which preserves the entire schema.  The only issue though is an SD from made in ArcMap =/= an SD from ArcGIS Pro.  So that means you can't simply overwrite the service in AGOL if the service was originally created in ArcMap (such as ones that were published to get around the other glaring issue of publishing from ArcGIS Pro).

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.

KellyGerrow
Esri Frequent Contributor

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

0 Kudos
ChrisBlinn1
Occasional Contributor

Hi Kelly,

I was able to get it working with the following workflow.

  1. Create a new SD from a new map in ArcGIS Pro 2.2.x.  Also, do not use an imported map from ArcMap (if anyone can tell me why, you get a cookie - this is baffling me).
  2. Uninstall ArcGIS Pro 2.2.x (I used 2.2.3).
  3. Install ArcGIS Pro 2.1.x (I used 2.1.0).
  4. Publish SD to ArcGIS Online using script above.
  5. I still had issues with relationship names.  I fixed this using the admin REST operations to delete from definition the relationships then add to definition the relationships with the correct names.  This is NOT a fun process, and you need to make sure both the service and all layers have their definitions updated accordingly.

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.

KellyGerrow
Esri Frequent Contributor

Hi Tom,

I don't believe this functionality is available through ArcMap. I'd suggest using the Python for this.

-Kelly

0 Kudos