I have found some very useful solutions to change MXD data sources using python. The question: Is it possible to automatically switch MXD data sources to an AGO-hosted feature service? It seems that the replaceDataSource() method would work, but there does not appear to be a workspace_type for AGO.
The added challenge here is that the feature class names change - the original file GDB uses the full name (i.e. "Major_Employers") and on AGO the name becomes the number for the REST service (i.e. "0").
I tried modifying the python example "A feature class is renamed" from the Esri help document and it didn't work. Before I move forward with troubleshooting this code, my main question is can this be done in the first place?
Note: I modified the AGO URL in my code example below to remove specifics:
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\temp\MXD_Update\Data_Source_Update.mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("DATASOURCE"):
if lyr.dataSource == r"C:\temp\MXD_Update\AGO_Sync_Testing.gdb\Major_Employers":
lyr.replaceDataSource(r"http://services2.arcgis.com/[url]/ArcGIS/rest/services/[featureservicename]/FeatureServer", "NONE", "0")
lyr.name = "0"
mxd.saveACopy(r"C:\temp\MXD_Update\Data_Source_Update_AGO.mxd")
del mxd