geohaskett

Script Not Working When Published as GeoProcessing Service

Discussion created by geohaskett on Mar 11, 2014
Latest reply on Oct 28, 2015 by deleted-user-mezzanRtr2IZ
Hello.

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.  Any suggestions as to what might be wrong with my script or settings?

# 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:
  agentNO = arcpy.GetParameterAsText(0) 
  reportFolderDated = "C:/arcgisserver/gisData/projects/RFIs/results/"
  reportFolder = "C:/inetpub/wwwroot/flexviewers/_supportDocs/reports/"
  pngPath = "C:/arcgisserver/gisData/projects/RFIs/reportTemplates/RFI_Report.png"
  rlfPath = "C:/arcgisserver/gisData/projects/RFIs/reportTemplates/RFI_Report.rlf"
  pdfReport = reportFolder+"RFIreport.pdf"
  pdfDatedReport = reportFolderDated+"Agent"+agentNO+"_{}.pdf".format(datetime.strftime(datetime.now(),"%Y-%m-%d_%H%M"))
  print "Variables Established"

  arcpy.env.overwriteOutput = True

  ### Establish Local Variables for Reports
  mxdReportMap = "C:/arcgisserver/gisData/projects/RFIs/reportTemplates/RFI_Report.mxd"  
  mxd = arcpy.mapping.MapDocument(mxdReportMap)
  df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
  lyr = arcpy.mapping.ListLayers(mxd, "Nexus DB", df)[0]

  ### Generate report
  pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfDatedReport)
  whereClause = "AGENTNUMBER = "+str(agentNO)+" AND LAT_DEC > "+str(0)
  print "Query: " + whereClause
  lyr.definitionQuery = whereClause
  print "Features Selected"
  df.extent = lyr.getSelectedExtent()
  arcpy.mapping.ExportToPNG(mxd,pngPath,resolution=200)
  print "PNG exported."
  arcpy.AddMessage("PNG Exported")
  arcpy.mapping.ExportReport(report_source=lyr,report_layout_file=rlfPath,output_file=pdfDatedReport)
  pdfDoc.saveAndClose()

  if os.path.exists(pdfReport):
    os.remove(pdfReport)
  print "check pdf"
  print "PDF Report Compiled."
  arcpy.AddMessage("PDF Report Compiled")
  print "Validate Report."
  shutil.copy(pdfDatedReport,pdfReport)
##  arcpy.SelectLayerByAttribute_management(lyr,"CLEAR_SELECTION")

except:
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "Oops, you have PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n" \
    + str(sys.exc_type) + ": " + str(sys.exc_value) + "\n"
    msgs = "Oops, you have ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n"
    arcpy.AddError(msgs)
    arcpy.AddError(pymsg)
    arcpy.AddMessage(msgs)
    arcpy.AddMessage(pymsg)
    arcpy.AddMessage(arcpy.GetMessages(1))

Outcomes