We have 3 employees with varying levels of computer savvy who need to generate several unique maps each day to be shared via one of the web app templates. I'm trying to automate as much of that process as possible. I can publish a feature service and share it with its appropriate group using arcpy in 10.1. I managed to figure out how to add Access and Use Constraints and Credits to the Feature Service Definition (I'm no XML/minidom guru). Is there a way to configure the Feature Pop-ups as well, setting the pop-up title to a certain field, and the contents to another?The biggest problem is having to manually add the feature service to a map and save the map. That means typing in consistent titles, tags (which are critical for searching in the web app), and summary, and then manually entering the Access and Use Constraints and Credits before sharing the map. Can I generate a Service Definition for a whole map which includes the feature service layer? I could then enter the metadata for the map as I have for the feature layer. The basemap is not critical for this so I just allow the web app to default and then provide user options to change it.I hope this makes sense. ThanksPaulI'm posting the code snippet that deals with the Service Definitions in case it's helpful:import arcpy
import sys
import traceback
import os
import datetime
import xml.dom.minidom as DOM
try:
## The following code is adapted from code posted to the ESRI forum by Jeff Moulds, ESRI
mapDoc = mxd
sddraft = os.path.join( workspace, 'HostedMS.sddraft')
## Parse out date, city and maxCategory (eps)
categories = ["Good","Moderate","Unhealthy for Sensitive Groups","Unhealthy","Very Unhealthy","Hazardous","Hazardous"]
maxCategory = categories[maxGridCode-1]
(month, day, year, hour, minute) = parseDate(filebase)
## some date, time, city parsing / string snippet construction
sddraftSummary = "PM2.5 data from " + city + ", AK, collected on " + date + time
sddraftTags = ",".join(["PM2.5,Air Quality,Sniffer Map",city,maxCategory])
service = city + " " + date + " starting " + str(hour) + str(minute)
serverType = 'MY_HOSTED_SERVICES'
onlineDirectory = "Sniffer_Maps" # this doesn't work
tellMe("Running CreateMapSDDraft ...")
arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, serverType, folder_name=onlineDirectory, summary=sddraftSummary, tags=sddraftTags)
### Returns python Dict of 'errors', 'messages', and 'warnings'
### Need to set data frame extent and projection
con = 'My Hosted Services'
workspace = os.path.dirname(workspace)
tellMe("Placing Service Definition files in: " + workspace)
sd = os.path.join(workspace,service + '.sd')
# Read the sddraft xml.
doc = DOM.parse(sddraft)
# Change service from map service to feature service
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName we want to disable.
if typeName.firstChild.data == "MapServer":
typeName.firstChild.data = "FeatureServer"
#Turn off caching
configProps = doc.getElementsByTagName('ConfigurationProperties')[0]
propArray = configProps.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "isCached":
# turn on caching
keyValue.nextSibling.firstChild.data = "false"
disclaimer = 'Pre-defined disclaimer'
disclaimNode = doc.createTextNode(disclaimer)
acc = doc.getElementsByTagName("AccessInformation")[0]
acc.appendChild(disclaimNode)
credits = "Pre-defined Credits"
cre = doc.getElementsByTagName("Credits")[0]
credNode = doc.createTextNode(credits)
cre.appendChild(credNode)
tellMe("Writing XML ...")
outXml = os.path.join(workspace,'HostedMSNew.sddraft')
f = open(outXml, 'w')
doc.writexml( f )
f.close()
tellMe("Running AnalyzeForSD ...")
analysis = arcpy.mapping.AnalyzeForSD(outXml)
if len(analysis['errors'])>0:
tellMe( str(analysis))
sys.exit(analysis['errors'])
#arcpy.SignOutFromPortal_server()
## tellMe("Signing In ...")
## username = "*****"
## password = "*****"
## arcpy.SignInToPortal_server(username,password,"http://www.arcgis.com/")
tellMe("Running StageService_server ...")
arcpy.StageService_server(outXml, sd)
tellMe("Running UploadServiceDefinition_server ...")
sharegroup = "Sniffer Map Feature Layer Services"
override = "OVERRIDE_DEFINITION"
arcpy.UploadServiceDefinition_server(sd, con, in_override=override, in_groups=sharegroup)
finally:
tellMe("Cleaning up scratch MXD.")
arcpy.mapping.RemoveLayer(df, lyrs[0])
mxd.save()
del mxd