<?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: Script Not Working When Published as GeoProcessing Service in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/script-not-working-when-published-as-geoprocessing/m-p/694147#M22997</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Return at least "Error" messages for the service under the service properties &amp;gt; Parameters and run the tool again.&amp;nbsp; Check the server logs for the error returned.&amp;nbsp; That will give you a good start on troubleshooting.&amp;nbsp; You can post the error you see here as well.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Mar 2014 21:57:35 GMT</pubDate>
    <dc:creator>JonathanQuinn</dc:creator>
    <dc:date>2014-03-18T21:57:35Z</dc:date>
    <item>
      <title>Script Not Working When Published as GeoProcessing Service</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/script-not-working-when-published-as-geoprocessing/m-p/694145#M22995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the following script that works fine when I run it via ArcGIS, however after publishing it to a GeoProcessing service using 10.2, it fails to run properly.&amp;nbsp; Any suggestions as to what might be wrong with my script or settings?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Importing Modules
import os,arcpy,sys,traceback,time,shutil
from datetime import datetime
from arcpy import env


### Establish Local Variables For Exporting Reports
print "*****************************************"
print "Welcome to the Agent RFI Report tool."
print "Establishing local variables..."
arcpy.AddMessage("Establishing Variables")
print ""

try:
&amp;nbsp; agentNO = arcpy.GetParameterAsText(0) 
&amp;nbsp; reportFolderDated = "C:/arcgisserver/gisData/projects/RFIs/results/"
&amp;nbsp; reportFolder = "C:/inetpub/wwwroot/flexviewers/_supportDocs/reports/"
&amp;nbsp; pngPath = "C:/arcgisserver/gisData/projects/RFIs/reportTemplates/RFI_Report.png"
&amp;nbsp; rlfPath = "C:/arcgisserver/gisData/projects/RFIs/reportTemplates/RFI_Report.rlf"
&amp;nbsp; pdfReport = reportFolder+"RFIreport.pdf"
&amp;nbsp; pdfDatedReport = reportFolderDated+"Agent"+agentNO+"_{}.pdf".format(datetime.strftime(datetime.now(),"%Y-%m-%d_%H%M"))
&amp;nbsp; print "Variables Established"

&amp;nbsp; arcpy.env.overwriteOutput = True

&amp;nbsp; ### Establish Local Variables for Reports
&amp;nbsp; mxdReportMap = "C:/arcgisserver/gisData/projects/RFIs/reportTemplates/RFI_Report.mxd"&amp;nbsp; 
&amp;nbsp; mxd = arcpy.mapping.MapDocument(mxdReportMap)
&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
&amp;nbsp; lyr = arcpy.mapping.ListLayers(mxd, "Nexus DB", df)[0]

&amp;nbsp; ### Generate report
&amp;nbsp; pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfDatedReport)
&amp;nbsp; whereClause = "AGENTNUMBER = "+str(agentNO)+" AND LAT_DEC &amp;gt; "+str(0)
&amp;nbsp; print "Query: " + whereClause
&amp;nbsp; lyr.definitionQuery = whereClause
&amp;nbsp; print "Features Selected"
&amp;nbsp; df.extent = lyr.getSelectedExtent()
&amp;nbsp; arcpy.mapping.ExportToPNG(mxd,pngPath,resolution=200)
&amp;nbsp; print "PNG exported."
&amp;nbsp; arcpy.AddMessage("PNG Exported")
&amp;nbsp; arcpy.mapping.ExportReport(report_source=lyr,report_layout_file=rlfPath,output_file=pdfDatedReport)
&amp;nbsp; pdfDoc.saveAndClose()

&amp;nbsp; if os.path.exists(pdfReport):
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove(pdfReport)
&amp;nbsp; print "check pdf"
&amp;nbsp; print "PDF Report Compiled."
&amp;nbsp; arcpy.AddMessage("PDF Report Compiled")
&amp;nbsp; print "Validate Report."
&amp;nbsp; shutil.copy(pdfDatedReport,pdfReport)
##&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr,"CLEAR_SELECTION")

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; tb = sys.exc_info()[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; tbinfo = traceback.format_tb(tb)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; pymsg = "Oops, you have PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n" \
&amp;nbsp;&amp;nbsp;&amp;nbsp; + str(sys.exc_type) + ": " + str(sys.exc_value) + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp; msgs = "Oops, you have ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(msgs)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(pymsg)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(msgs)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(pymsg)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages(1))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Mar 2014 19:13:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/script-not-working-when-published-as-geoprocessing/m-p/694145#M22995</guid>
      <dc:creator>GeorgeHaskett</dc:creator>
      <dc:date>2014-03-11T19:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Script Not Working When Published as GeoProcessing Service</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/script-not-working-when-published-as-geoprocessing/m-p/694146#M22996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You did not say what failed when you ran your tool.&amp;nbsp; I assume that this is a single machine on which you have both ArcMap and ArcGIS Server installed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have never written a GP tool but I am trying to understand the process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ArcGIS Server runs as a specific user.&amp;nbsp; By default it creates a user whose name is "arcgis".&amp;nbsp; That account must have access to all the files that you reference in your script.&amp;nbsp; If you login as user arcgis does the script run correctly from ArcMap?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2014 18:25:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/script-not-working-when-published-as-geoprocessing/m-p/694146#M22996</guid>
      <dc:creator>RichardWatson</dc:creator>
      <dc:date>2014-03-18T18:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Script Not Working When Published as GeoProcessing Service</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/script-not-working-when-published-as-geoprocessing/m-p/694147#M22997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Return at least "Error" messages for the service under the service properties &amp;gt; Parameters and run the tool again.&amp;nbsp; Check the server logs for the error returned.&amp;nbsp; That will give you a good start on troubleshooting.&amp;nbsp; You can post the error you see here as well.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2014 21:57:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/script-not-working-when-published-as-geoprocessing/m-p/694147#M22997</guid>
      <dc:creator>JonathanQuinn</dc:creator>
      <dc:date>2014-03-18T21:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Script Not Working When Published as GeoProcessing Service</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/script-not-working-when-published-as-geoprocessing/m-p/694148#M22998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi George,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You've probably already discovered this as this post is pretty old now, but ExportReport will not function as a geoprocessing service and is the likely cause of your gp service failure (it is for me running 10.3).&amp;nbsp; Have you found a workaround for this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jeff&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Oct 2015 17:35:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/script-not-working-when-published-as-geoprocessing/m-p/694148#M22998</guid>
      <dc:creator>deleted-user-mezzanRtr2IZ</dc:creator>
      <dc:date>2015-10-28T17:35:03Z</dc:date>
    </item>
  </channel>
</rss>

