<?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 Re: Add feature to map and upload as web layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479082#M70658</link>
    <description>&lt;P&gt;Hi Brandon,&lt;/P&gt;&lt;P&gt;Actually I'm using this code sample from the same page, the lines you mentioned are not used by me.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# Sign in to portal
arcpy.SignInToPortal("https://www.arcgis.com", "MyUserName", "MyPassword")

# Set output file names
outdir = r"C:\Project\Output"
service_name = "FeatureSharingDraftExample"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)

# Reference layers to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
selected_layer = m.listLayers()[0]
selected_table = m.listTables()[0]

# Create FeatureSharingDraft
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name, [selected_layer, selected_table])

# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)

# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)

# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, server_type)

print("Finish Publishing")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this code actually works if&amp;nbsp; I drag and drop the data from geodatabase into the&amp;nbsp; project view and then run the publish code.&lt;/P&gt;&lt;P&gt;It doesn't work when I use&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selected_layer = m.addDataFromPath(shape_in_gdb)&lt;/LI-CODE&gt;&lt;P&gt;to do this step, which confused me.&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Ziqing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 May 2024 11:25:11 GMT</pubDate>
    <dc:creator>ZiqingYu</dc:creator>
    <dc:date>2024-05-27T11:25:11Z</dc:date>
    <item>
      <title>Add feature to map and upload as web layer</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1478227#M70653</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use python to upload a web layer as&amp;nbsp;&amp;nbsp;&lt;A href="https://pro.arcgis.com/de/pro-app/3.1/tool-reference/server/upload-service-definition.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/de/pro-app/3.1/tool-reference/server/upload-service-definition.htm&lt;/A&gt;&amp;nbsp;shows, if the layer is already in the map view, everything is ok&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZiqingYu_0-1716540852862.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/105290iFD8E3A3961981777/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZiqingYu_0-1716540852862.png" alt="ZiqingYu_0-1716540852862.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;however, I want to upload the data directly from geodatabase, and I don't know what to do. Here's what I tried:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZiqingYu_1-1716541409709.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/105291i325778D1D5C7FC73/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZiqingYu_1-1716541409709.png" alt="ZiqingYu_1-1716541409709.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the error I got:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZiqingYu_2-1716541427611.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/105292iA76AA0EC81238D6F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZiqingYu_2-1716541427611.png" alt="ZiqingYu_2-1716541427611.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;what should I do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 09:06:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1478227#M70653</guid>
      <dc:creator>ZiqingYu</dc:creator>
      <dc:date>2024-05-24T09:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature to map and upload as web layer</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1478229#M70654</link>
      <description>&lt;P&gt;To non German speaker: the error means: The chosen Layer hat no required layer-typ for web-feature-layer, object: map&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 09:10:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1478229#M70654</guid>
      <dc:creator>ZiqingYu</dc:creator>
      <dc:date>2024-05-24T09:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature to map and upload as web layer</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1478605#M70656</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/799868"&gt;@ZiqingYu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm assuming we used the same code sample and part of that sample has something like this in it:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#read draft file
docs = DOM.parse(sddraftpath)
key_list = docs.getElementsByTagName('Key')
value_list = docs.getElementsByTagName('Value')

#Sharing level
Share_Organization = "false"
Share_Everyone = "false"
Share_Group = "true"

#Sharing to Deed Notice Inspection Tool Group
GroupID = ""#set sharing values
for i in range(key_list.length):
    if key_list[i].firstChild.nodeValue == "PackageUnderMyOrg":
        value_list[i].firstChild.nodeValue = Share_Organization
    if key_list[i].firstChild.nodeValue == "PackageIsPublic":
        value_list[i].firstChild.nodeValue = Share_Everyone
    if key_list[i].firstChild.nodeValue == "PackageShareGroups":
        value_list[i].firstChild.nodeValue = Share_Group
    if Share_Group == "true" and key_list[i].firstChild.nodeValue == "PackageGroupIDs":
        value_list[i].firstChild.nodeValue = GroupID

#write to sddraftfile
f = open(sddraftpath, 'w')
docs.writexml(f)
f.close()&lt;/LI-CODE&gt;&lt;P&gt;I have this same issue and I just discovered today that removing line 23-26 removes the error and allows it to publish. Hope this helps&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 18:53:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1478605#M70656</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-05-24T18:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature to map and upload as web layer</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479082#M70658</link>
      <description>&lt;P&gt;Hi Brandon,&lt;/P&gt;&lt;P&gt;Actually I'm using this code sample from the same page, the lines you mentioned are not used by me.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# Sign in to portal
arcpy.SignInToPortal("https://www.arcgis.com", "MyUserName", "MyPassword")

# Set output file names
outdir = r"C:\Project\Output"
service_name = "FeatureSharingDraftExample"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)

# Reference layers to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
selected_layer = m.listLayers()[0]
selected_table = m.listTables()[0]

# Create FeatureSharingDraft
server_type = "HOSTING_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "FEATURE", service_name, [selected_layer, selected_table])

# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)

# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)

# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, server_type)

print("Finish Publishing")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this code actually works if&amp;nbsp; I drag and drop the data from geodatabase into the&amp;nbsp; project view and then run the publish code.&lt;/P&gt;&lt;P&gt;It doesn't work when I use&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selected_layer = m.addDataFromPath(shape_in_gdb)&lt;/LI-CODE&gt;&lt;P&gt;to do this step, which confused me.&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Ziqing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2024 11:25:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479082#M70658</guid>
      <dc:creator>ZiqingYu</dc:creator>
      <dc:date>2024-05-27T11:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature to map and upload as web layer</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479494#M70662</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/799868"&gt;@ZiqingYu&lt;/a&gt;&amp;nbsp;would you be surprised to find out the the fix I implemented last week does not work today and I am now receiving the error again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do use add data from path as my script creates new layers and tables that are being published. When I add the feature manually I still receive the error though.&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2024 13:21:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479494#M70662</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-05-28T13:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature to map and upload as web layer</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479558#M70666</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/799868"&gt;@ZiqingYu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since you pointed out the .addDataFromPath was causing the issue I was able to reproduce that as the cause of the error.&lt;/P&gt;&lt;P&gt;I found that using .addDataFromPath then restarting ArcPro and running the block of code where I attempt to publish will work 100% of the time (&lt;EM&gt;5/5 times to be exact).&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;So I assumed that the map object just needed to be refreshed: adding this line of code seems to work for me test and let me know if it works for you. I have this done before I create the sddraft using .getWebLayerSharingDraft().&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
aprx.closeViews("MAPS")
aprx.listMaps("Map")[0].openView()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2024 14:41:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479558#M70666</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-05-28T14:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature to map and upload as web layer</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479609#M70670</link>
      <description>&lt;P&gt;try this instead&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("Current")
### Bug Fix ###
aprx.closeViews("MAPS")
aprx.listMaps("Map")[0].openView()
aprx.save()&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 28 May 2024 16:06:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479609#M70670</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-05-28T16:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature to map and upload as web layer</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479979#M70682</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/640285"&gt;@BrandonMcAlister&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;this works perfectly! thank you very much!&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Ziqing&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 06:56:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-to-map-and-upload-as-web-layer/m-p/1479979#M70682</guid>
      <dc:creator>ZiqingYu</dc:creator>
      <dc:date>2024-05-29T06:56:14Z</dc:date>
    </item>
  </channel>
</rss>

