Select to view content in your preferred language

How to configure a python web tool with file output

1488
1
10-06-2020 07:46 AM
TobiSellekaerts
Regular Contributor

I need to publish a python-based web tool which will output an html file.  I have the code working in ArcGIS Pro (2.6), and can publish it successfully. Everything seems to work except the output is not 'returned' to the user. 

1. At the start, to ensure it was working, I set the output to be a standard

arcpy.GetParameterAsText(#)

and chose an output file interactively.  In Pro, the script runs and the file is generated correctly.  When published (to a hosting server, 10.8), the script also works as expected but the output is not yet 'returned' to the user.

2. So I modified the script to put the output file in the scratch folder:

outputFile = os.path.join(arcpy.env.scratchFolder, "webtool_output.html")

This also works in Pro (although I don't see the output), and publishes and runs successfully in a Portal Web App, but the output isn't returned to the user.

3. I found this page:

Geoprocessing service to return a file 

and added

arcpy.SetParameter(0, file.name)

to the end of my code, but this throws an error in ArcGIS Pro (so won't publish as a service.) 

4. It seems like the answer to my question should be found here:

Input and output parameters—ArcGIS Pro | Documentation 

I think I would be able to work it out if I could find a functioning example.

0 Kudos
1 Reply
TobiSellekaerts
Regular Contributor

Many thanks to Anthony Giles of esri for getting me closer to the solution.

On this page:

Tutorial: Print a web map and export a vector output PDF document using ArcPy—ArcGIS Server | Docume... 

1. I learned that my output parameter line in the code needed to look like this:

arcpy.SetParameterAsText(1, outputFile)

and voila! The code works in pro and after republishing and running an HTML file is generated on the hosting server in C:\arcgisserver\directories\arcgisjobs\.......\webtool_output.html

However, the output tab of the geoprocessing widget shows nothing. (No errors, but no link to the output either.)

2. From the above link I also learned I had neglected to define the output parameter in the ArcGIS Pro Tool Properties.  Even if the user isn't queried to select an output filename, I still needed to define the output file parameter (Data Type: File, type: Derived, Direction: output).  Reran, republished, but the output tab is stubbornly blank.

3. From this page:

https://community.esri.com/thread/176433 

I tried changing the output from derived to required, but it still hasn't fixed the problem.

0 Kudos