Select to view content in your preferred language

Custom PrintTask works but returns "Null" for result.url

1510
2
Jump to solution
03-04-2014 06:50 AM
JaniceBaird
Frequent Contributor
I have a custom PrintTask which I created following the Advanced Printing Tutorial. When I execute the PrintTask, the pdf is created and resides in the arcgisjobs folder on my GIS Server. I can open the pdf manually but I can not get it to open using window.open(result.url). The result url is null. If I examine the result object, I see that it is an esri DataFile with a url property that is null.

Has anyone else created a custom PrintTask with different results? How do I get the path and file name returned when the print task completes if the result object does not have the url?

Here is my code:

function advancedPrint(printScale) {     require(["esri/SpatialReference", "esri/tasks/PrintTask", "esri/tasks/PrintTemplate", "esri/tasks/PrintParameters"], function (SpatialReference, PrintTask, PrintTemplate, PrintParameters) {         var printURL = dataLink + "/Test/AdvancedPrint/GPServer/AdvancedPrint"         var printTask = new PrintTask(printURL, { async: true });         var formatOpt = getFormat();         var printLayout = getLayout();         var sr = new SpatialReference(102748);         var printParams = new PrintParameters();         printParams.map = map;         printParams.outSpatialReference = sr;         printParams.extraParameters = { mapExtent: map.extent, printToScale: printScale };         var printTemplate = new PrintTemplate();         printTemplate.format = formatOpt;         printTemplate.layout = printLayout; // "Letter ANSI A Landscape";         printTemplate.preserveScale = false;         printTemplate.layoutOptions = {             titleText: dijit.byId("txtPrintTitle").value,             authorText: dijit.byId("txtPrintAuthor").value,             copyrightText: "Copyright 2014",             scalebarUnit: "Miles"         };         printParams.template = printTemplate;         // Progress bar         var i = 0;         var progressBar = dijit.byId("progressBar");         var progressGo = setInterval(function () {             progressBar.set("value", i++ % 100);         }, 300);         setTimeout(function () { clearInterval(progressGo); }, 10000);         // Execute Print Task         printTask.execute(printParams, printComplete);     }); }  function printComplete(result) {     window.open(result.url);     var progressBar = dijit.byId("progressBar");     progressBar.label = "Print Complete"; }



Thanks,
Janice.
0 Kudos
1 Solution

Accepted Solutions
JaniceBaird
Frequent Contributor
How embarrassing... I totally left out a line in my python script. Everything was going great and the script was doing exactly what I told it to do... it even neglected to return the output as suggested by my spiffy coding!

If you want your python to return the result, don't forget this line:

# Set the output parameter to be the output file of the server job
arcpy.SetParameterAsText(4, Output_File)


thanks to Erwin @ esri technical support for pointing me in the right direction!

Janice.

View solution in original post

0 Kudos
2 Replies
JaniceBaird
Frequent Contributor
I have also discovered that my custom print task will not accept changes to parameters other than scale. The print task expects the parameters as shown in the attachment and the print parameters that are supplied to the printTask execute method are also shown. The parameters are submitted to the task as entered by the user but the PrintTask creates only a PDF in Landscape (if that is how I publish the geoprocessing service). If I publish the service using Portrait orientation, I get portrait even if I submit with Landscape. I deleted all of the defaults from the script tool and republished but this did not help. I am using Layout Templates which reside on the server and at this time am only trying to print to Letter ANSI A Landscape and Letter ANSI A Portrait. I have mxd's and if I modify the mxd's and republish, my modifications show up in the print output.

Maybe I need help on publishing. Maybe I need help on setting print parameters. I just know I need help!

Here is the Rest Endpoint: http://www.skagitcounty.net/publicgis/rest/services/Test/AdvancedPrint/GPServer/AdvancedPrint

Here is my python:
import arcpy
import os
import uuid

# Input WebMap json
Web_Map_as_JSON = arcpy.GetParameterAsText(0)

# The template location in the server data store
templatePath = '//gisvm1/resources/Layout_Templates/'

# The input format for output
outputFormat = arcpy.GetParameterAsText(1)
if outputFormat == '#' or not outputFormat:
    outputFormat = "PDF"

# The input layout template
templateMxd = arcpy.GetParameterAsText(2)
if templateMxd == '#' or not templateMxd:
    templateMxd = "Letter ANSI A Landscape"

# Extra Parameters
# Extent
mapExtent = arcpy.GetParameterAsText(3)
# Scale
printToScale = arcpy.GetParameterAsText(4)

# Convert the WebMap to a map document
templateMxd = os.path.join(templatePath, templateMxd + '.mxd')
result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON, templateMxd)
mxd = result.mapDocument

# Reference the data frame that contains the webmap
# Note: ConvertWebMapToMapDocument renames the active dataframe in the template mxd to "Webmap"
df = arcpy.mapping.ListDataFrames(mxd, 'Webmap')[0]

# Set data frame scale
if printToScale and printToScale != '#':
    df.scale = printToScale

# Remove the service layer
# This will just leave the vector layers from the template
#for lyr in arcpy.mapping.ListLayers(mxd, data_frame=df):
#    if lyr.isServiceLayer:
#        arcpy.mapping.RemoveLayer(df, lyr)

# Use the uuid module to generate a GUID as part of the output name
# This will ensure a unique output name
output = 'ap_{}'.format(str(uuid.uuid1()))
Output_File = os.path.join(arcpy.env.scratchFolder, output)

# Export the WebMap
if outputFormat == "PDF":
    Output_File = Output_File + ".pdf"
    arcpy.mapping.ExportToPDF(mxd, Output_File)
elif outputFormat == "JPG":
    Output_File = Output_File + ".jpg"
    arcpy.mapping.ExportToJPEG(mxd, Output_File)

# Clean up - delete the map document reference
filePath = mxd.filePath
del mxd, result
os.remove(filePath)


Thanks,
Janice
0 Kudos
JaniceBaird
Frequent Contributor
How embarrassing... I totally left out a line in my python script. Everything was going great and the script was doing exactly what I told it to do... it even neglected to return the output as suggested by my spiffy coding!

If you want your python to return the result, don't forget this line:

# Set the output parameter to be the output file of the server job
arcpy.SetParameterAsText(4, Output_File)


thanks to Erwin @ esri technical support for pointing me in the right direction!

Janice.
0 Kudos