English

How To: Publish a feature layer without overwriting the editor tracking information

Summary

When publishing a feature layer to ArcGIS Online or Portal for ArcGIS with existing editor tracking fields, the information is overwritten and replaced with the publisher's information and the date or time the layer is published. This is by design. However, it is possible to preserve the pre-existing editor tracking information using ArcGIS API for Python.

Procedure

Follow the instructions below to publish a feature layer without overwriting the editor tracking information using ArcGIS API for Python.

Note:
Publish the desired feature service from ArcGIS Pro before proceeding with these steps.
Insert the following script to overwrite the existing feature layer and retain the original values of the editor tracking information:
pub_params = {"editorTrackingInfo" : {"enableEditorTracking":'true', "preserveEditUsersAndTimestamps":'true'}}
sdItem.update(data=sd)
print('Overwriting existing feature service…')
fs = sdItem.publish(publish_parameters=pub_params,overwrite=True)
  1. Import the necessary modules.
import arcpy
import os, sys
from arcgis.gis import GIS
  1. Specify the path to the project and the login credentials.
prjPath = r'C:\Users\pathwayToYour.aprx'

sd_fs_name = 'name of item in the portal'
portal = 'https://PortalURL/portal/home' #or https://arcgis.com
user = 'username'
password = 'password'
  1. Set the sharing options, a local path in the machine to store the temporary content, and create a new Service Definition Draft (.sddraft) file and stage to Service Definition (SD).
shrOrg = True
shrEveryone = False
shrGroups = ''

relPath = sys.path[0]
sddraft = os.path.join(relPath, 'WebUpdate.sddraft')
sd = os.path.join(relPath, 'WebUpdate.sd')

print('Creating SD file')
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps()[0]
arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, "MY_HOSTED_SERVICES", "FEATURE_ACCESS", None, True, True, True)
arcpy.StageService_server(sddraft, sd)
  1. Connect to the specified portal.
print('Connecting to {}'.format(portal))
gis = GIS(portal, user, password)
#if single sign on, edit line above be gis = GIS(portal)
  1. Find the SD file, update and overwrite the feature layer edits, including the snippet to preserve the timestamps.
print('Search for original SD on portal…')
sdItem = gis.content.search('{} AND owner:{}'.format(sd_fs_name, user), item_type='Service Definition')[0]
print('Found SD: {}, ID: {} n Uploading and overwriting…'.format(sdItem.title, sdItem.id))
pub_params = {"editorTrackingInfo" : {"enableEditorTracking":'true', "preserveEditUsersAndTimestamps":'true'}}
sdItem.update(data=sd)
print('Overwriting existing feature service…')
fs = sdItem.publish(publish_parameters=pub_params,overwrite=True)
fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)
print('Finished updating: {} – ID: {}'.format(fs.title, fs.id))

Related Information

Last Published: 8/20/2020

Article ID: 000021839

Software: ArcGIS API for Python 1.8.2, 1.8.1, 1.8.0, 1.7.1, 1.7.0, 1.6.1, 1.6, 1.5.3, 1.5.2, 1.5.1, 1.5, 1.4.1, 1.4, 1.3, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2, 1.0.1, 1.0 ArcGIS Online 8.2 Portal for ArcGIS 10.8.1, 10.8