arcpy.mp.CreateWebLayerSDDraft

2440
11
07-06-2016 03:53 PM
ChetEgbert1
New Contributor II

The documentation here: CreateWebLayerSDDraft—ArcPy | ArcGIS for Desktop does not show samples of using this command with the optional parameters.  I am having no luck using any parameters beyond service_type.  The parameters seam to be ignored.  Though the draft is created successfully it goes in the default ArcGIS Online user folder and no description, summary etc. values make it to the published service listing.  Has anybody got good working examples using optional parameters?

0 Kudos
11 Replies
DanPatterson_Retired
MVP Esteemed Contributor

so did you move on to the other steps listed in the help topic?

These tools just permit automation of existing tools, sos there is some presumption that you already have everything ready to go, just like you would for doing the manual process.  It is recommended that you go through the workflow once at least manually to ensure that the whole workflow... which may require several tools... is what you want.

If you only have to do this infrequently, then there is little point bring arcpy into the equation at all.

0 Kudos
ChetEgbert1
New Contributor II

Thanks for the reply.  The command works to prepare the draft.  I have successfully published the prepared draft using the arcpy StageService and UploadServiceDefinition commands.  The trouble is the CreateWebLayerSDDraft command does not pass on the summary, description, credits, and tags I specify.  It is as if I had not used them.  It also does not pay any mind to the folder I specify. 

As a work around I have been able to get the draft published in the right ArcGIS Online folder and display description and tags using the upload and publish REST endpoint’s arguments.  I have not been able to find a way to get summary and credits populated, however, as they are not exposed on these endpoints.

Ideally I could just automate the population of the ArcGIS Pro's Map's Properties/Metadata panel.  It seams that what you put there always winds up in the right place on the ArcGIS Online published service's pages.  I can't find an API to populate those ArcGIS Pro Map fields.

An ESRI tech recommends that the summary, description, tags, and credits be specified as follows:  summary='mysum', description='mydesc' etc which is not immediately apparent in the documentation as there is no example of optional parameter usage.  I can't get that to work either from pasting code into ArcGIS Pro's Python window.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

But the description for the tool gives the requirements for the parameters, for example

tags

A string that represents the tags. Multiple tags can be added or separated by a comma or semicolon.

(The default value is None)

meaning it would be "tag1, tag2, tag3" or (their wording is confusing) "tag1", "tag2", "tag3".  I do think their use of the word OR is off.

If it is the former, it is a comma separated string, so I presume that the parsing of the string follows standard python parsing syntax.

Give one a shot since I suspect not many people are doing what you want to do

0 Kudos
LeonS
by
Occasional Contributor II

Hi Chet,

Here is a snippet of the command using the optional parameters that I use:

arcpy.mp.CreateWebLayerSDDraft(m, draft_sd, service_name, 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS', folder_name, enable_editing = edit_enabled, allow_exporting = export_enabled, summary=itemsummary, tags = itemtags, credits = itemcredits, use_limitations = itemuselimits)

I run into the same issue that it does not update the tags and some other information of the SD file on the item details page, as I would expect. Curiously, if you view the metadata for the SD item from the item details page it appears to update some items like the tags and credit information do get updated.  For some reason, those updates are not carried over to the item details page.  Bug?

I used the ArcGIS API for Python to update the item information on the published feature service.  Might be worth taking a look at.

ArcGIS API for Python | ArcGIS for Developers 

Leon

0 Kudos
MollyWatson1
Occasional Contributor

I also have the same issue. The tool populates the use limitations on the item details page but none of the other parameters that I have specified (summary, description, tags, etc). Additionally, the overwrite existing service parameters works when I run the tool on my test feature service. However, when I run it on my working feature service, I get an error that "User can't overwrite this service, using this data, as this data is already referring to another service." The only thing I changed in my Python code was the name of the test feature service to the working feature service. It definitely seems buggy to me.

0 Kudos
ChetEgbert1
New Contributor II

I understand metadata a little better now.  There are three kinds of metadata.  There is the metadata that describes a map, an ArcGIS project.  There is metadata that describes a layer, as in layerfile.  There is metadata that describes a datasource, the original standard GIS dataset metadata.  Components from these types of metadata wind up on AGOL Feature services which may have many Feature layers within them.  Each Feature layer indexed within a Feature service represents an original GIS dataset.  ESRI should provide a good crosswalk to document metadata and distinguish source to destination of each important metadata component through the publishing process.

My most recent publishing routine captures metadata components satisfactorily.

First I add a datasource to ArcGIS Pro. On the Layer Properties' Metadata panel notice the 'Copy data source's metadata to this layer' button.  If you click this button many fields of metadata on the datasource will transfer to the layerfile.  I save the layerfile after clicking this button.  It seams the layerfile is an important carrier of metadata components through the publishing process.

I then use getWebLayerSharingDraft, exportToSDDraft, and StageService to prepare the package.

Finally, I use REST url to upload and publish:

https://"+g_Portal+"/sharing/rest/content/users/<user>/addItem

https://"+g_Portal+"/sharing/rest/content/users/<user>/publish

0 Kudos
DougEaton
New Contributor II

I'm having the same issue, but with the "enable_editing" parameter.  Even though I have it set to true (my code is below), it seems to ignore that setting, as it does not allow editing.  When I publish the feature layer manually, editing works fine.  Any ideas?  

arcpy.mp.CreateWebLayerSDDraft(map_or_layers=mp,
                                   out_sddraft=sddraft,
                                   service_name=sd_fs_name,
                                   server_type="MY_HOSTED_SERVICES",
                                   service_type="FEATURE_ACCESS",
                                   folder_name="JULIE_FOLDER",
                                   overwrite_existing_service=True,
                                   copy_data_to_server=False,
                                   enable_editing=True,
                                   allow_exporting=False,
                                   enable_sync=False,
                                   summary=None,
                                   tags=None,
                                   description=None,
                                   credits=None,
                                   use_limitations=None)
0 Kudos
MollyWatson1
Occasional Contributor

Hi Doug,

I was having a similar issue where sometimes my script would overwrite and sometimes it wouldn't. I contacted ESRI technical support and we figured out that the CreateWebLayerSDDraft tool is actually old and has been replaced with a newer tool - WebLayerSharingDraft.  After I switched to that tool, my issues were resolved. I also use a list to loop through all of my content to ensure I have a correct match with the feature service name. That also seemed to help resolve my issues. Here's a snippet of my code:

# Create a new SDDraft and stage to SD for summary data
print("Creating SD file")
sharing_draft = mp.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", sd_fs_name)
sharing_draft.summary = "My Summary"
sharing_draft.tags = "My tags"
sharing_draft.description = "My description"
sharing_draft.credits = "My credits"
sharing_draft.use = "My disclaimer"

# Create Service Definition Draft file
sharing_draft.exportToSDDraft(sddraft)

# Stage Service
arcpy.StageService_server(sddraft, sd)

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

#Check that it found the correct layer
list = gis.content.search(query=sd_fs_name,item_type="Service Definition")
i = 0
while list.title != sd_fs_name:
     i += 1
print("")
print('MATCH FOUND!')
print(f'item.title = {list.title}, sd_fs_name = {sd_fs_name}')
item = list # define item based on above findings
item.update(data=sd) # use sd to update hosted "Service Definition" file
print("Overwriting existing feature service")
fs = item.publish(overwrite=True) # publish "Service Definition"

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

DougEaton
New Contributor II

Molly,

Thank you very much.  I will try that tool instead and I like the idea of looping through the content to ensure a correct match with the feature service name as well.

Doug

0 Kudos