Referencing the current open map document from a webtool

12-08-2020 07:50 AM
New Contributor III

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  the following:


aprx ='CURRENT')
map_ = aprx.activeMap


 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:



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?


Full code is below:


import arcpy

aprx ='CURRENT')
map_ = aprx.activeMap

for layer in map_.listLayers():
    conProps = layer.connectionProperties
    conProps['connection_info']['db_connection_properties'] = '<mydatabase>'
    conProps['connection_info']['instance'] = 'sde:postgresql:<mydatabase>'
    conProps['connection_info']['server'] = '<mydatabase>'
    layer.updateConnectionProperties(layer.connectionProperties, conProps)


Tags (3)
0 Kudos
0 Replies