Enable Sync capability on a read-only feature service with Python

1908
3
Jump to solution
08-09-2016 02:27 PM
GregSmith2
New Contributor III


I have written a Python script tool that publishes map services for my organization. It works great, except that I am trying to publish read-only feature services with the "Sync" capability for offline mobile use. After following examples from Esri/other forums, I set the capabilities in my script by parsing the service definition draft as an xml document, as shown here:

# turn on feature access if service is editable
if service.endswith("Editable") or service.endswith("Redlining") or allowSync:

  featAccessSettings = doc.getElementsByTagName("TypeName")

   for featAccessSetting in featAccessSettings:

   if featAccessSetting.firstChild.data == "FeatureServer":

  featAccessSetting.parentNode.getElementsByTagName("Enabled")[0].firstChild.data = "true"
   configProps = doc.getElementsByTagName("Info")[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 == "WebCapabilities":

   if (service.endswith("Editable")) or (service.endswith("Redlining")):

  keyValue.nextSibling.firstChild.data == "Query,Create,Update,Delete,Uploads,Editing"
   else:

  keyValue.nextSibling.firstChild.data == "Query,Sync"

On the last line, to create a read-only feature service (according to this guide: Prepare data for offline use—Documentation | ArcGIS for Server ), I set the web capabilities to only Query and Sync, but when the tool completes running, the publish service still has full editing capabilities and Sync disabled. If I try to publish the service with the user interface inside ArcMap or ArcCatalog, the web capability settings come across correctly.

Is there another parameter that needs to be set programmatically, that I am missing here? I know the data has to be configured correctly to use Sync, but again, the data I've been testing with works fine when published though the UI.

Thanks!

Greg

0 Kudos
1 Solution

Accepted Solutions
GregSmith2
New Contributor III

Okay, so I have finally gotten to the bottom of this. Turns out that when parsing the xml document of the sddraft to enable feature access web capabilities, as enumerated in the Esri help guide for ArcPy (CreateMapSDDraft—Help | ArcGIS for Desktop ), grabbing the dom element by tag name 'Info' at index [0] returns the Mapping capabilities for the service (which are set to Data, Map, Query by default), and not the actual Feature Access capabilities for editing and syncing. The correct index (inside the portion of the following screenshot highlighted in red) should actually be [7].

That is, if you are doing your parsing with xml.minidom like the guide shows. I actually changed my code to use xml.etree instead of xml.minidom to parse the sddraft, so for me the index was [6], but I coded it to exclude the first instance of the tag 'Info' since it was not a child of the tags in the query.

Not sure how many people will run into this again, but Esri may want to update their help guide .

Kind regards,

Greg Smith

View solution in original post

3 Replies
JeffSegal
New Contributor III

An alternative method is to disable editing on AGOL.

0 Kudos
GregSmith2
New Contributor III

Jeff-

Thank you for your response! I probably should have clarified- the services my tool handles are not being published to AGOL. Rather, the tool publishes to my organization's ArcGIS Server. Unfortunately, I cannot disable edits across the board because some of our services being published do need to have editing capabilities. My tool iterates through multiple map documents in a batch, so that is why I am trying to have the option to enable sync on specified ones, to avoid any additional configuration after the fact.

0 Kudos
GregSmith2
New Contributor III

Okay, so I have finally gotten to the bottom of this. Turns out that when parsing the xml document of the sddraft to enable feature access web capabilities, as enumerated in the Esri help guide for ArcPy (CreateMapSDDraft—Help | ArcGIS for Desktop ), grabbing the dom element by tag name 'Info' at index [0] returns the Mapping capabilities for the service (which are set to Data, Map, Query by default), and not the actual Feature Access capabilities for editing and syncing. The correct index (inside the portion of the following screenshot highlighted in red) should actually be [7].

That is, if you are doing your parsing with xml.minidom like the guide shows. I actually changed my code to use xml.etree instead of xml.minidom to parse the sddraft, so for me the index was [6], but I coded it to exclude the first instance of the tag 'Info' since it was not a child of the tags in the query.

Not sure how many people will run into this again, but Esri may want to update their help guide .

Kind regards,

Greg Smith