<?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 Referencing the current open map document from a webtool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/referencing-the-current-open-map-document-from-a/m-p/1007729#M59233</link>
    <description>&lt;P&gt;Hi, I recently wrote a small script that takes all the layer sourcing in the currently open map (ArcPro 2.5.1) over to a new database contained in enterprise. I have several team members that also need to use this tool as we migrate from one db to another and republish our templates in the new enterprise portal. I thought a webtool would be the best way to share this tool rather than emailing the code out and showing each member how to set up the ArcPro Script tool. The publishing of the tool worked great, but when I pull it in I keep getting an error when I try to reference&amp;nbsp; the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject('CURRENT')
map_ = aprx.activeMap&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This code works if the script tool is run locally without error but when the gp tool is pulled into pro from portal and run from there, I get the following error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JasonVignochi_0-1607442248126.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/1686i6910657B18A2D5E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JasonVignochi_0-1607442248126.png" alt="JasonVignochi_0-1607442248126.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I have to explicitly request for a project as a parameter as well as a map document? Or is there something I am missing between running a script tool locally vs over portal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Full code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

aprx = arcpy.mp.ArcGISProject('CURRENT')
map_ = aprx.activeMap

for layer in map_.listLayers():
    conProps = layer.connectionProperties
    conProps['connection_info']['db_connection_properties'] = '&amp;lt;mydatabase&amp;gt;'
    conProps['connection_info']['instance'] = 'sde:postgresql:&amp;lt;mydatabase&amp;gt;'
    conProps['connection_info']['server'] = '&amp;lt;mydatabase&amp;gt;'
    layer.updateConnectionProperties(layer.connectionProperties, conProps)

aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Dec 2020 15:50:06 GMT</pubDate>
    <dc:creator>JasonVignochi</dc:creator>
    <dc:date>2020-12-08T15:50:06Z</dc:date>
    <item>
      <title>Referencing the current open map document from a webtool</title>
      <link>https://community.esri.com/t5/python-questions/referencing-the-current-open-map-document-from-a/m-p/1007729#M59233</link>
      <description>&lt;P&gt;Hi, I recently wrote a small script that takes all the layer sourcing in the currently open map (ArcPro 2.5.1) over to a new database contained in enterprise. I have several team members that also need to use this tool as we migrate from one db to another and republish our templates in the new enterprise portal. I thought a webtool would be the best way to share this tool rather than emailing the code out and showing each member how to set up the ArcPro Script tool. The publishing of the tool worked great, but when I pull it in I keep getting an error when I try to reference&amp;nbsp; the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject('CURRENT')
map_ = aprx.activeMap&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This code works if the script tool is run locally without error but when the gp tool is pulled into pro from portal and run from there, I get the following error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JasonVignochi_0-1607442248126.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/1686i6910657B18A2D5E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JasonVignochi_0-1607442248126.png" alt="JasonVignochi_0-1607442248126.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I have to explicitly request for a project as a parameter as well as a map document? Or is there something I am missing between running a script tool locally vs over portal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Full code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

aprx = arcpy.mp.ArcGISProject('CURRENT')
map_ = aprx.activeMap

for layer in map_.listLayers():
    conProps = layer.connectionProperties
    conProps['connection_info']['db_connection_properties'] = '&amp;lt;mydatabase&amp;gt;'
    conProps['connection_info']['instance'] = 'sde:postgresql:&amp;lt;mydatabase&amp;gt;'
    conProps['connection_info']['server'] = '&amp;lt;mydatabase&amp;gt;'
    layer.updateConnectionProperties(layer.connectionProperties, conProps)

aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 15:50:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-the-current-open-map-document-from-a/m-p/1007729#M59233</guid>
      <dc:creator>JasonVignochi</dc:creator>
      <dc:date>2020-12-08T15:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing the current open map document from a webtool</title>
      <link>https://community.esri.com/t5/python-questions/referencing-the-current-open-map-document-from-a/m-p/1289186#M67645</link>
      <description>&lt;P&gt;This is a great idea. Unfortunately, the way web tools work doesn't allow access to your current ArcGIS project. The process runs on the enterprise machine, so it needs a reference to the .aprx files from that machine. So, &lt;STRONG&gt;no&lt;/STRONG&gt; &lt;EM&gt;&lt;STRONG&gt;arcpy.mp.ArcGISProject('CURRENT')&lt;/STRONG&gt;&lt;/EM&gt; in web tools.&lt;/P&gt;&lt;P&gt;Here's an alternative you could use if you and your team have a shared network drive that the enterprise server could access.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
# add .aprx file location 
aprx_file_location = arcpy.GetParameterAsText(0)
#aprx = arcpy.mp.ArcGISProject('CURRENT')
aprx = arcpy.mp.ArcGISProject(aprx_file_location)
for map_ in aprx.listMaps():
    for layer in map_.listLayers():
        conProps = layer.connectionProperties
        conProps['connection_info']['db_connection_properties'] = '&amp;lt;mydatabase&amp;gt;'
        conProps['connection_info']['instance'] = 'sde:postgresql:&amp;lt;mydatabase&amp;gt;'
        conProps['connection_info']['server'] = '&amp;lt;mydatabase&amp;gt;'
        layer.updateConnectionProperties(layer.connectionProperties, conProps)

aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;You could possibly expand this using &lt;A title="ArcPy da Walk documentation" href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/walk.htm" target="_blank" rel="noopener"&gt;arcpy.da.Walk&lt;/A&gt; to fix all .aprx files in a shared folder.&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 15:47:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-the-current-open-map-document-from-a/m-p/1289186#M67645</guid>
      <dc:creator>Ken_Doman</dc:creator>
      <dc:date>2023-05-15T15:47:45Z</dc:date>
    </item>
  </channel>
</rss>

