Updating Editor Tracking Data in a Hosted Feature Service (Online)

3622
10
03-21-2019 09:38 AM
ScottMoore__Olympia_
Esri Contributor
12 10 3,622

With the 3/19/19 release of ArcGIS Online, some changes were made to the admin API for hosted feature services (ArcGIS Online only) that make it possible to update editor tracking data as an administrator in ArcGIS Online.  Why would you need to do this?  Well, the way editor tracking (also known as Keep track of who created and last updated features) works, is that when a new feature is created in a hosted feature service, 4 fields are automatically populated with data about who created and last edited a feature and when those operations happened.  Those fields look like this:

As you can see, I have 5 features that are "owned" by ScottMooreRAD meaning that the ArcGIS Online user ScottMooreRAD initially created the feature on 3/19/2019 at 10:57AM.  Notice that the Editor and EditDate fields are also populated when the feature is first created.

Now, what happens if ScottMooreRAD no longer works at my agency?  We need to be able to reassign ownership of ScottMooreRAD's features, especially when we have OBAC (ownership based access control) enabled.  NOTE: Feature Service owners (and certain others) can edit all features in the Map Viewer when they Add layer to new map with full editing control, but this does not affect the Creator attribute.

If we have the feature service set to only allow editors to edit their own features, and the user that owns the feature no longer exists, then we would be stuck in terms of being able to edit those features.  So, how can we update these system managed fields so we assign the features to a new user?  Let's run a simple ArcGIS API for Python script!

The first step is to connect to ArcGIS Online using the ArcGIS API for Python and get access to the feature service.  You should connect as the owner of the feature service.  Notice that we have also setup 2 variables for the current owner (fromUser) and the owner we would like to take over ownership of features (toUser).  We also have 4 variables for the field names that are used for the editor tracking fields.  In some cases, your field names may be different and this makes it easy for us to change.

Now, the real work begins.  We need to disable editor tracking:

Next, we need to make the editor tracking fields editable.

Now that they are editable, we can run a calculate expression to update the fromUser (ScottMooreRAD) to the toUser (ScottMoorePNW).  

Notice in the python code above that I have 3 commented out fields.  If you would like to update the other editor tracking fields for some reason, you can also update the creation and last edit dates as well as the last editor.  Simply uncomment those lines and put in your own logic.

The final step we need to take is to make the editor tracking fields read-only (editable: False), and to turn editor tracking back on.

Now, let's validate that the Creator is set to our new user.  As we can see, the features that were owned by ScottMooreRAD are now owned by ScottMoorePNW.

Attached, you will find a python notebook that you can start from.  Let me know in the comments if you have any questions!

10 Comments