I've created a model in ArcGIS Pro ModelBuilder which attempts to carry out the following:
- Variable: Database connection (sql server)
- Make Query Layer (input = Database Connection, output = "Dwellings SQL")
- Make Feature Layer (input = "Dwellings SQL", output = "Dwellings")
Then using the code in the following resource:
I created a toolbox which should publish (overwrite) a layer called "Dwellings" in our AGOL account. I have tweaked the code in the ScriptTool function as such:
def ScriptTool(map, service, summary, tags, description, overwriteService, enableEditing, enableSync, enableWFS, timezone, share_public, share_organization, share_groups, outdir): """ScriptTool function docstring""" # Set output file names sddraft_filename = service + ".sddraft" sddraft_output_filename = os.path.join(outdir, sddraft_filename) # Reference map to publish aprx = arcpy.mp.ArcGISProject("CURRENT") m = aprx.listMaps(map)[0] selected_layer = m.listLayers()[0] # Create FeatureSharingDraft and set service properties sharing_draft = m.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", service, [selected_layer]) sharing_draft.summary = summary sharing_draft.tags = tags sharing_draft.description = description sharing_draft.credits = "My Credits" sharing_draft.useLimitations = "My Use Limitations" sharing_draft.overwriteExistingService = overwriteService # Create Service Definition Draft file sharing_draft.exportToSDDraft(sddraft_output_filename) outsddraft = sddraft_output_filename arcpy.AddMessage("Service definition draft created") # Modify capabilities if enableEditing or enableSync: ModifyCapabilities(sddraft_output_filename, enableEditing, enableSync) if enableWFS: EnableWFS(sddraft_output_filename) # Set time zone if(timezone != ""): property_set = [{ "key": "dateFieldsRespectsDayLightSavingTime", "value": "true" }, { "key": "dateFieldsTimezoneID", "value": timezone }] SetTimezone(sddraft_output_filename, property_set=property_set) # Create Service Definition file sd_filename = service + ".sd" sd_output_filename = os.path.join(outdir, sd_filename) arcpy.StageService_server(sddraft_output_filename, sd_output_filename) arcpy.AddMessage("Service definition created") # Upload to portal output = arcpy.UploadServiceDefinition_server(sd_output_filename, "My Hosted Services", in_override="OVERRIDE_DEFINITION", in_public=share_public, in_organization=share_organization, in_groups=share_groups) arcpy.AddMessage("Service published") return output[5] ...so that the function will publish a feature layer rather than the whole map. On running the code I receive the following error:
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\server.py", line 1179, in StageService raise e File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\server.py", line 1176, in StageService retval = convertArcObjectToPythonObject(gp.StageService_server(*gp_fixargs((in_service_definition_draft, out_service_definition, staging_version), True))) File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing_base.py", line 512, in return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: ERROR 001272: Analyzer errors were encountered ([{"code":"00102","message":"Selected layer does not contain a required layer type for web feature layer","object":"Map"}]). Failed to execute (StageService).
Failed script Publish Web Feature Layer... Failed to execute (Publish Web Feature Layer).
I can't understand why this is happening as the current map does display the imported feature layer and when running the section of the code under #Reference map to publish in the python console it does find the "Dwellings" feature layer. The line of code which throws the error is:
arcpy.StageService_server(sddraft_output_filename, sd_output_filename) ...and the error message isn't very helpful, I can't find any helpful documentation on Esri's website which details if the problem is with the feature layer or a bug in the code.
I am using ArcGIS Pro 3.1.3 with the default arcgispro-py3 environment.
Below is a diagram of my model:
Below are the parameters I used as per the Esri article:

