Updating Feature layers with Standalone Tables

10-23-2020 10:49 AM
New Contributor

Hi everyone. 

I am currently tasked with developing an automated workflow from Arc Pro to a Dashboard hosted on AGOL. In Pro, I have a symbolized map layer with about eight standalone tables. I add the map to the dashboard and use the standalone tables to create serial charts and indicators. 

The issue I keep running into is that when I attempt to update my feature layer on AGOL, the layer and/or standalone tables will either duplicate or will not update entirely. I am using the cookie-cutter code provided by ESRI for updating web content, but I am not sure what I am missing. 

Any thoughts?


import sys, os, tempfile, json, logging, arcpy, fnmatch, shutil, subprocess, arcgis
from arcgis.gis import GIS
from arcgis.mapping import WebMap

### Start setting variables
# Set the path to the project
prjPath = r"pathToProject.aprx"

# Update following variables to match
portal = r'http://www.arcgis.com'
user = r'USER'
password = r'PASSWORD'

# Set sharing options
shrOrg = False
shrEveryone = False
shrGroups = ""

### End setting variables

# Local paths to create temporary content
relPath = os.path.dirname(prjPath)
sddraft = os.path.join(relPath, "WebUpdate.sddraft")
sd = os.path.join(relPath, "WebUpdate.sd")

# Create a new SDDraft and stage to 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','',True, True)
arcpy.StageService_server(sddraft, sd)

print('Connecting to {}'.format(portal))
gis = GIS(portal, user, password)

# Find the SD, update it, publish with overwrite and set sharing and metadata
print('Searching 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))
print('Overwriting existing feature service...')
fs = sditem.publish(overwrite=True)

if shrOrg or shrEveryone or shrGroups:
    print('Setting sharing options...')
    fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)

print('Finishing updating: {} - ID: {}'.format(fs.title, fs.id))
Tags (3)
0 Kudos
0 Replies