<?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 Broken data links after publishing as geoprocessing service in ArcGIS Enterprise Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-questions/broken-data-links-after-publishing-as/m-p/708315#M27094</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am in the process of developing a tool as a Python Toolbox to be published as a Geoprocessing Service using ArcGIS for Server 10.3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After publishing and running my tool from a sandbox environment I am encountering broken links between the two .lyr files set as the output parameters in and the two Feature Classes that serve as their Data Sources.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Investigation into the issue seems to indicate that the link between .lyr file and Feature Class, made as the final step in the Toolbox using the following method...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;g_ESRI_variable_3 = os.path.join(arcpy.env.packageWorkspace,u'tooldata') #one of many variables automatically created after publishing to server

(...)

toolDataPath = g_ESRI_variable_3
gdbpath = os.path.join(toolDataPath, "data.gdb")&amp;nbsp;&amp;nbsp; # base staging data used every time the rool is executed
arcpy.env.scratchWorkspace = '\\\\aus1-gds-darc01/data-store/ToolData/scratch/scratch.gdb'&amp;nbsp; 
env.workspace = arcpy.env.packageWorkspace
scratch = env.scratchGDB
scratchfolder = env.scratchFolder

(...)

# replace datasources of .lyr files to link with respective feature classes
lyr1 = arcpy.mapping.Layer(outlayerfileL)
lyr1.name = "legend" + nowstring
lyr1.replaceDataSource(scratch, 'FILEGDB_WORKSPACE', "legend" + nowstring, True)
lyr1.save()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: helvetica;"&gt;... is not kept once the output data is copied from Server's pre-designated scratch location to the location where outputs from processed jobs are kept.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="92456" alt="TOC.png" class="image-2 jive-image" height="140" src="https://community.esri.com/legacyfs/online/92456_TOC.png" style="height: 140px; width: 180.869565217391px;" width="181" /&gt; &lt;IMG __jive_id="92458" alt="MMAP_tree.png" class="image-3 jive-image" height="165" src="https://community.esri.com/legacyfs/online/92458_MMAP_tree.png" style="width: 246px; height: 165.718562874252px;" width="245" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="92377" alt="Properties.png" class="image-1 jive-image" height="287" src="https://community.esri.com/legacyfs/online/92377_Properties.png" style="width: 364px; height: 287.098591549296px;" width="365" /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: helvetica;"&gt;There are no other errors in running the tool nor does it fail unless the subset of data attempted is too large.&amp;nbsp; The data source link can be repaired&amp;nbsp; manually after running using the typical methods.&amp;nbsp; This problem does not occur when the Python Toolbox is run locally.&amp;nbsp; Is there anything I can do to the code published to server that can fix this?&amp;nbsp; I'm hesitant to attempt to do so.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: helvetica;"&gt;Thank you in advance for any advice.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 05:45:14 GMT</pubDate>
    <dc:creator>gregorymavian</dc:creator>
    <dc:date>2021-12-12T05:45:14Z</dc:date>
    <item>
      <title>Broken data links after publishing as geoprocessing service</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/broken-data-links-after-publishing-as/m-p/708315#M27094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am in the process of developing a tool as a Python Toolbox to be published as a Geoprocessing Service using ArcGIS for Server 10.3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After publishing and running my tool from a sandbox environment I am encountering broken links between the two .lyr files set as the output parameters in and the two Feature Classes that serve as their Data Sources.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Investigation into the issue seems to indicate that the link between .lyr file and Feature Class, made as the final step in the Toolbox using the following method...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;g_ESRI_variable_3 = os.path.join(arcpy.env.packageWorkspace,u'tooldata') #one of many variables automatically created after publishing to server

(...)

toolDataPath = g_ESRI_variable_3
gdbpath = os.path.join(toolDataPath, "data.gdb")&amp;nbsp;&amp;nbsp; # base staging data used every time the rool is executed
arcpy.env.scratchWorkspace = '\\\\aus1-gds-darc01/data-store/ToolData/scratch/scratch.gdb'&amp;nbsp; 
env.workspace = arcpy.env.packageWorkspace
scratch = env.scratchGDB
scratchfolder = env.scratchFolder

(...)

# replace datasources of .lyr files to link with respective feature classes
lyr1 = arcpy.mapping.Layer(outlayerfileL)
lyr1.name = "legend" + nowstring
lyr1.replaceDataSource(scratch, 'FILEGDB_WORKSPACE', "legend" + nowstring, True)
lyr1.save()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: helvetica;"&gt;... is not kept once the output data is copied from Server's pre-designated scratch location to the location where outputs from processed jobs are kept.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="92456" alt="TOC.png" class="image-2 jive-image" height="140" src="https://community.esri.com/legacyfs/online/92456_TOC.png" style="height: 140px; width: 180.869565217391px;" width="181" /&gt; &lt;IMG __jive_id="92458" alt="MMAP_tree.png" class="image-3 jive-image" height="165" src="https://community.esri.com/legacyfs/online/92458_MMAP_tree.png" style="width: 246px; height: 165.718562874252px;" width="245" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="92377" alt="Properties.png" class="image-1 jive-image" height="287" src="https://community.esri.com/legacyfs/online/92377_Properties.png" style="width: 364px; height: 287.098591549296px;" width="365" /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: helvetica;"&gt;There are no other errors in running the tool nor does it fail unless the subset of data attempted is too large.&amp;nbsp; The data source link can be repaired&amp;nbsp; manually after running using the typical methods.&amp;nbsp; This problem does not occur when the Python Toolbox is run locally.&amp;nbsp; Is there anything I can do to the code published to server that can fix this?&amp;nbsp; I'm hesitant to attempt to do so.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: helvetica;"&gt;Thank you in advance for any advice.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:45:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/broken-data-links-after-publishing-as/m-p/708315#M27094</guid>
      <dc:creator>gregorymavian</dc:creator>
      <dc:date>2021-12-12T05:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Broken data links after publishing as geoprocessing service</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/broken-data-links-after-publishing-as/m-p/708316#M27095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: helvetica;"&gt;Solution seems to be to set up seperate local and server-based versions of arcpy.mapping.Layer.replaceDataSource:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;############################################################################################
######### replace datasources of .lyr files to link with respective feature classes - SERVER
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; serverbase = '\\\\aus1-hen-mmap01v'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; scratchcut = scratch[3:]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalocation = os.path.join(serverbase, scratchcut)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr1 = arcpy.mapping.Layer(outlayerfileL)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr1.name = "legend" + nowstring
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr1.replaceDataSource(datalocation, 'FILEGDB_WORKSPACE', "legend" + nowstring, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr1.save()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr2 = arcpy.mapping.Layer(outlayerfileO)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr2.name = "output" + nowstring
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr2.replaceDataSource(datalocation, 'FILEGDB_WORKSPACE', "output" + nowstring, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr2.save()
##########################################################################################
##########################################################################################
######### replace datasources of .lyr files to link with respective feature classes - LOCAL
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lyr1 = arcpy.mapping.Layer(outlayerfileL)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lyr1.name = "legend" + nowstring
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lyr1.replaceDataSource(scratch, 'FILEGDB_WORKSPACE', "legend" + nowstring, True)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lyr1.save()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lyr2 = arcpy.mapping.Layer(outlayerfileO)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lyr2.name = "output" + nowstring
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lyr2.replaceDataSource(scratch, 'FILEGDB_WORKSPACE', "output" + nowstring, True)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lyr2.save()
#&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;##########################################################################################&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: helvetica;"&gt;Since the post-publish modification doesn't change any of the code that Server automatically alters during publish, this seems to get the job done without much risk.&amp;nbsp; The 'serverbase' variable just needs to be altered in accordance with whatever server the script is being run on (e.g. normal deployment workflows and moving from a development server to a testing server, etc.).&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:45:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/broken-data-links-after-publishing-as/m-p/708316#M27095</guid>
      <dc:creator>gregorymavian</dc:creator>
      <dc:date>2021-12-12T05:45:16Z</dc:date>
    </item>
  </channel>
</rss>

