<?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: Creating a layer in Geoprocessing Service causes an error in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/creating-a-layer-in-geoprocessing-service-causes/m-p/307644#M10674</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm having the same issue and I think its because the layer in in the "GPInMemoryWorkspace" and not on a disk.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Oct 2015 21:11:28 GMT</pubDate>
    <dc:creator>TerryGustafson</dc:creator>
    <dc:date>2015-10-21T21:11:28Z</dc:date>
    <item>
      <title>Creating a layer in Geoprocessing Service causes an error</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/creating-a-layer-in-geoprocessing-service-causes/m-p/307642#M10672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have some logic in my Geoprocessing service that creates a layer in order to add it to a map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(map_document)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.management.MakeFeatureLayer(out_zone, "layer") #out_zone is an in_memory fc&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buffer_layer = arcpy.mapping.Layer("layer") #this doesn't work in the gp service&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, buffer_layer, "TOP")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works just fine in the script tool from ArcMap.&amp;nbsp; It publishes successfully as well.&amp;nbsp; But when I run the GP service I get an error on line 4 above.&amp;nbsp; I have some traceback error reporting and it says the line that is failing is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;buffer_layer = arcpy.mapping.Layer(g_Esri_variable_3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error I get is Object: CreateObject layer invalid data source&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So my question is what is g_Esri_variable_3?&amp;nbsp; What is ArcGIS Server doing differently than the desktop script tool?&amp;nbsp; Any suggestions on fixing this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jul 2013 15:53:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/creating-a-layer-in-geoprocessing-service-causes/m-p/307642#M10672</guid>
      <dc:creator>NilsBabel</dc:creator>
      <dc:date>2013-07-30T15:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a layer in Geoprocessing Service causes an error</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/creating-a-layer-in-geoprocessing-service-causes/m-p/307643#M10673</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I figured out a workaround.&amp;nbsp; I saved the layer to a layer file.&amp;nbsp; Then created the layer object from the layer file.&amp;nbsp; Still don't know why the original script works in desktop but not server.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jul 2013 19:35:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/creating-a-layer-in-geoprocessing-service-causes/m-p/307643#M10673</guid>
      <dc:creator>NilsBabel</dc:creator>
      <dc:date>2013-07-30T19:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a layer in Geoprocessing Service causes an error</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/creating-a-layer-in-geoprocessing-service-causes/m-p/307644#M10674</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm having the same issue and I think its because the layer in in the "GPInMemoryWorkspace" and not on a disk.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Oct 2015 21:11:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/creating-a-layer-in-geoprocessing-service-causes/m-p/307644#M10674</guid>
      <dc:creator>TerryGustafson</dc:creator>
      <dc:date>2015-10-21T21:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a layer in Geoprocessing Service causes an error</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/creating-a-layer-in-geoprocessing-service-causes/m-p/307645#M10675</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When publishing to server, certain variables are substituted for g_ESRI_variable_x and declared at the top of the script. Not sure why server needs to do this - some of the variables in my scripts are just field names, like g_ESRI_variable_4 = u'F_AREA'. You can see the amended script in the arcgissystem folder on the server, e.g. D:\arcgisserver\directories\arcgissystem\arcgisinput\LFP\lfp01Setup.GPServer\extracted\v101\_python\LFP_01_Setup.py&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the problem in your script may be to do with the current path. The &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/layer-class.htm"&gt;help doc&lt;/A&gt; says that the Layer constructor needs&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN style="color: #4d4d4d; font-family: 'Lucida Grande', 'Segoe UI', Arial, sans-serif;"&gt;A string that includes the full path and file name of an existing layer (&lt;/SPAN&gt;&lt;SPAN class="usertext" style="font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-weight: bold; color: #4d4d4d;"&gt;.lyr&lt;/SPAN&gt;&lt;SPAN style="color: #4d4d4d; font-family: 'Lucida Grande', 'Segoe UI', Arial, sans-serif;"&gt;) file.&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4d4d4d; font-family: 'Lucida Grande', 'Segoe UI', Arial, sans-serif;"&gt;Your script doesn't contain a path, so maybe the working folder is different when running on the server. Try specifying the full path for "layer" in lines 3 and 4.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2015 07:46:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/creating-a-layer-in-geoprocessing-service-causes/m-p/307645#M10675</guid>
      <dc:creator>JonMorris2</dc:creator>
      <dc:date>2015-10-22T07:46:45Z</dc:date>
    </item>
  </channel>
</rss>

