<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to overwrite a published map document as a service via Server in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-overwrite-a-published-map-document-as-a/m-p/127967#M9934</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following and needed help on getting this to work. I am unsure about the xml modification of sddraft syntax and order within the script. Any suggestions would be appreciated. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# ArcPy script to overwrite a published map document as a service via Server.&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;arcpy,sys&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Imported ArcPy"&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;xml.dom.minidom &lt;SPAN style="color: #000080; font-weight: bold;"&gt;as &lt;/SPAN&gt;DOM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# Set variables&lt;BR /&gt;&lt;/SPAN&gt;mxd = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r'sample.mxd'&lt;BR /&gt;&lt;/SPAN&gt;server_con = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'ARCGIS_SERVER'&lt;BR /&gt;&lt;/SPAN&gt;connection_file_path = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r"GIS Servers\ARCGIS on xyz (publisher)"&lt;BR /&gt;&lt;/SPAN&gt;service_name = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"themap"&lt;BR /&gt;&lt;/SPAN&gt;inFolderType = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"EXISTING"&lt;BR /&gt;&lt;/SPAN&gt;inFolder = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Test"&lt;BR /&gt;&lt;/SPAN&gt;inStartup = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"STARTED"&lt;BR /&gt;&lt;/SPAN&gt;newType = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'esriServiceDefinitionType_Replacement'&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# Set output path&lt;BR /&gt;&lt;/SPAN&gt;sddraft = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r'C:\Users\dunderwood\AppData\Local\ESRI\Desktop10.2\Staging\ARCGIS on GIS on xyz (publisher)\mapservice.sddraft'&lt;BR /&gt;&lt;/SPAN&gt;sd_file = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r'C:\Users\dunderwood\AppData\Local\ESRI\Desktop10.2\Staging\ARCGIS on GIS on xyz(publisher)\mapservice.sd'&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# Method to create a SD file to overwrite an existing service&lt;BR /&gt;&lt;/SPAN&gt;xml = sddraft&lt;/P&gt;&lt;P&gt;doc = DOM.parse(xml)&lt;/P&gt;&lt;P&gt;descriptions = doc.getElementsByTagName(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;'Type'&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;desc &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;descriptions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;desc.parentNode.tagName == &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'SVCManifest'&lt;/SPAN&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;desc.hasChildNodes():&lt;/P&gt;&lt;P&gt;&amp;nbsp; desc.firstChild.data = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'esriServiceDefinitionType_Replacement'&lt;BR /&gt;&lt;/SPAN&gt;outXml = xml&lt;/P&gt;&lt;P&gt;f = &lt;SPAN style="color: #000080;"&gt;open&lt;/SPAN&gt;(outXml, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'w'&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;doc.writexml(f)&lt;/P&gt;&lt;P&gt;f.close()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# 1 Create a service definition draft&lt;BR /&gt;&lt;/SPAN&gt;analysis_result = arcpy.mapping.CreateMapSDDraft(mxd, sddraft)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"SDdraft file created"&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# 2 Stage and create Service Definition file&lt;BR /&gt;&lt;/SPAN&gt;arcpy.StageService_server(sddraft, sd_file)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Service Definition file created"&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# 3 Publish the SD file as a service&lt;BR /&gt;&lt;/SPAN&gt;arcpy.UploadServiceDefinition_server(sd_file, connection_file_path, service_name,&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"#"&lt;/SPAN&gt;,inFolderType,inFolder,inStartup)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Service published successfully"&lt;/SPAN&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Jul 2016 19:44:14 GMT</pubDate>
    <dc:creator>DevinUnderwood2</dc:creator>
    <dc:date>2016-07-14T19:44:14Z</dc:date>
    <item>
      <title>How to overwrite a published map document as a service via Server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-overwrite-a-published-map-document-as-a/m-p/127967#M9934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following and needed help on getting this to work. I am unsure about the xml modification of sddraft syntax and order within the script. Any suggestions would be appreciated. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# ArcPy script to overwrite a published map document as a service via Server.&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;arcpy,sys&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Imported ArcPy"&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;xml.dom.minidom &lt;SPAN style="color: #000080; font-weight: bold;"&gt;as &lt;/SPAN&gt;DOM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# Set variables&lt;BR /&gt;&lt;/SPAN&gt;mxd = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r'sample.mxd'&lt;BR /&gt;&lt;/SPAN&gt;server_con = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'ARCGIS_SERVER'&lt;BR /&gt;&lt;/SPAN&gt;connection_file_path = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r"GIS Servers\ARCGIS on xyz (publisher)"&lt;BR /&gt;&lt;/SPAN&gt;service_name = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"themap"&lt;BR /&gt;&lt;/SPAN&gt;inFolderType = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"EXISTING"&lt;BR /&gt;&lt;/SPAN&gt;inFolder = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Test"&lt;BR /&gt;&lt;/SPAN&gt;inStartup = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"STARTED"&lt;BR /&gt;&lt;/SPAN&gt;newType = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'esriServiceDefinitionType_Replacement'&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# Set output path&lt;BR /&gt;&lt;/SPAN&gt;sddraft = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r'C:\Users\dunderwood\AppData\Local\ESRI\Desktop10.2\Staging\ARCGIS on GIS on xyz (publisher)\mapservice.sddraft'&lt;BR /&gt;&lt;/SPAN&gt;sd_file = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;r'C:\Users\dunderwood\AppData\Local\ESRI\Desktop10.2\Staging\ARCGIS on GIS on xyz(publisher)\mapservice.sd'&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# Method to create a SD file to overwrite an existing service&lt;BR /&gt;&lt;/SPAN&gt;xml = sddraft&lt;/P&gt;&lt;P&gt;doc = DOM.parse(xml)&lt;/P&gt;&lt;P&gt;descriptions = doc.getElementsByTagName(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;'Type'&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;desc &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;descriptions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;desc.parentNode.tagName == &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'SVCManifest'&lt;/SPAN&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;desc.hasChildNodes():&lt;/P&gt;&lt;P&gt;&amp;nbsp; desc.firstChild.data = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'esriServiceDefinitionType_Replacement'&lt;BR /&gt;&lt;/SPAN&gt;outXml = xml&lt;/P&gt;&lt;P&gt;f = &lt;SPAN style="color: #000080;"&gt;open&lt;/SPAN&gt;(outXml, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'w'&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;doc.writexml(f)&lt;/P&gt;&lt;P&gt;f.close()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# 1 Create a service definition draft&lt;BR /&gt;&lt;/SPAN&gt;analysis_result = arcpy.mapping.CreateMapSDDraft(mxd, sddraft)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"SDdraft file created"&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# 2 Stage and create Service Definition file&lt;BR /&gt;&lt;/SPAN&gt;arcpy.StageService_server(sddraft, sd_file)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Service Definition file created"&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-style: italic;"&gt;# 3 Publish the SD file as a service&lt;BR /&gt;&lt;/SPAN&gt;arcpy.UploadServiceDefinition_server(sd_file, connection_file_path, service_name,&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"#"&lt;/SPAN&gt;,inFolderType,inFolder,inStartup)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Service published successfully"&lt;/SPAN&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jul 2016 19:44:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-overwrite-a-published-map-document-as-a/m-p/127967#M9934</guid>
      <dc:creator>DevinUnderwood2</dc:creator>
      <dc:date>2016-07-14T19:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to overwrite a published map document as a service via Server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-overwrite-a-published-map-document-as-a/m-p/127968#M9935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried testing\running it Devin? I've tried this same sample script with updating AGOL services, so I would assume it would work. If there is an error then kindly update this thread.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Jul 2016 05:26:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-overwrite-a-published-map-document-as-a/m-p/127968#M9935</guid>
      <dc:creator>ChrisPedrezuela</dc:creator>
      <dc:date>2016-07-17T05:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to overwrite a published map document as a service via Server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-overwrite-a-published-map-document-as-a/m-p/127969#M9936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for taking the time to look at this.&lt;/P&gt;&lt;P&gt;I get the following error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:/Users/dunderwood/Documents/AutomatePublishWebLayers/Overwrite_Map_Service.py", line 24, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doc = DOM.parse(xml)&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Python27\ArcGIS10.2\lib\xml\dom\minidom.py", line 1921, in parse&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return expatbuilder.parse(file)&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Python27\ArcGIS10.2\lib\xml\dom\expatbuilder.py", line 922, in parse&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fp = open(file, 'rb')&lt;/P&gt;&lt;P&gt;IOError: [Errno 2] No such file or directory: 'C:\\Users\\dunderwood\\AppData\\Local\\ESRI\\Desktop10.2\\Staging\\ARCGIS on xyz (publisher)\mapservice.sddraft'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jul 2016 14:08:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-overwrite-a-published-map-document-as-a/m-p/127969#M9936</guid>
      <dc:creator>DevinUnderwood2</dc:creator>
      <dc:date>2016-07-18T14:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to overwrite a published map document as a service via Server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-overwrite-a-published-map-document-as-a/m-p/127970#M9937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Devin, sorry for being a year and half late, but I see two issues with the script.&amp;nbsp; The first, and cause of your error, is the position of the xml modification bit.&amp;nbsp; That needs to go in between steps 1 and 2,&amp;nbsp; the sddraft has not been created yet and the xml functions can't find the file to&amp;nbsp;modify.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second bit that may cause you issue are the lines&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI style="background-color: #ffffff; border: 0px;"&gt;"&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #000080; border: 0px; font-weight: bold;"&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;desc.hasChildNodes():"&lt;/LI&gt;&lt;/UL&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;and&lt;/P&gt;&lt;UL&gt;&lt;LI style="background-color: #ffffff; border: 0px;"&gt;&amp;nbsp; desc.firstChild.data =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; border: 0px; font-weight: bold;"&gt;'esriServiceDefinitionType_Replacement'&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2018 13:28:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-overwrite-a-published-map-document-as-a/m-p/127970#M9937</guid>
      <dc:creator>EricTran</dc:creator>
      <dc:date>2018-10-26T13:28:47Z</dc:date>
    </item>
  </channel>
</rss>

