Hi All
I have a feature class that I have symbolized using Arcade combining two fields to create different symbols; something like this:
var code = $feature.FIELD1
var state = $feature.FIELD2
if (code == '0' && state == 'Unknown' ||
code == '1' && state == 'State 1' ||
code == '1' && state == 'State 2') {
return 'Symbol 1';
}
else if (code == '2' && state == 'Unknown' ||
code == '2' && state == 'State 2' ||
code == '2' && state == 'State 3') {
return 'Symbol 2';
}
else {
return 'Symbol 3';
}
This works fine, I have done it for 20 categories. When I publish this layer as a Web Layer using "Sharing\Share as a Web Layer" in ArcGIS PRO the service is published keeping the symbology (the ARCADE expression is kept and transferred into the Portal). The service definition file (.sd) is also created without any problem and published into the Portal.
If I want to do the same using a python script to automate the process the python shell gives me some warnings:
WARNING 002893: Analyzer warnings were encountered ([{"code":"24041","message":"Layer does not have a feature template set","object":"MY LAYER"}].
It publishes the web service, but I only get an unique point symbol (the Arcade symbology get lost in the process). If I define the symbology, in Portal using Arcade, when I try to overwrite the web services, also using a python script the symbology change to an unique symbol (as I was expecting, because it seems the service definition file is not recognizing the Arcade expression when using python).
The code that I am using is something like this:
import arcpy
import os
from arcgis.gis import GIS
arcpy.env.overwriteOutput = True
# Sign in to portal
arcpy.SignInToPortal('My portal', 'MyUserName', 'MyPassword')
# Set output file names
outdir = "My folder"
service = "Service_name"
sddraft_filename = service + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
print (sddraft_output_filename)
# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"path with my project.aprx")
print (aprx)
for maps in aprx.listMaps("My map"):
print (maps.name," map read from my project")
for lyr in maps.listLayers("MY LAYER"):
print (lyr.name," layer read from my project")
# Create FeatureSharingDraft and set service properties
print ("Creating Sharing Draft...")
sharing_draft = maps.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", service)
sharing_draft.summary = "My summary"
sharing_draft.tags = "My tags"
sharing_draft.description = "My description"
sharing_draft.credits = "My credits"
sharing_draft.useLimitations = "My use limitations"
sharing_draft.portalFolder = "The Portal folder name"
# Create Service Definition Draft file
print ("Exporting Service Definition Draft File...")
sharing_draft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print ("Staging service...")
sd_filename = service + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
print (sd_output_filename)
print("Creating ",sd_filename),
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)
print (arcpy.GetMessages())
# Publish to server
print("Uploading Service Definition...")
# Set local variables
inServer = "HOSTING_SERVER"
# Execute UploadServiceDefinition
arcpy.UploadServiceDefinition_server(in_sd_file=sd_output_filename, in_server=inServer, in_service_name=service, in_cluster="default", in_folder_type="EXISTING", in_folder="The Portal folder name", in_startupType="STARTED", in_override="OVERRIDE_DEFINITION", in_my_contents="SHARE_ONLINE", in_public="PRIVATE", in_organization="NO_SHARE_ORGANIZATION", in_groups="Groups that I want to share with")
print("Successfully Uploaded service.")
Is there a limitation for the function to transfer the Arcade expression when using arcpy?. Or Am I missing something in the process?. Any help would be appreciated.
Thanks,
Andres
I am seeing something similar. Do you ever resovle?
Hi Jonathan
I solved the problem calculating a new field with the categories I wanted to use, but using code blocks within the Python Script.