HOW TO
When publishing a feature layer from ArcGIS Pro to ArcGIS Online or Portal for ArcGIS, it is possible to enable or disable the existing editor information. However, in ArcGIS Pro 2.5 and below, when publishing from ArcGIS Pro 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.
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.
Download OverwriteExistingFeatureLayer.zip and extract the OverwriteExistingFeatureLayer.txt file. Insert the script to overwrite the existing feature layer and retain the original values of the editor tracking information:
import arcpy import os, sys from arcgis.gis import GIS
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'
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)
print('Connecting to {}'.format(portal)) gis = GIS(portal, user, password) #if single sign on, edit line above be gis = GIS(portal)
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))
Article ID: 000021839
Get help from ArcGIS experts
Download the Esri Support App