Select to view content in your preferred language

Create Geoprocessing Service from Python Script Tool for use in Web App Builder

580
1
11-13-2023 01:37 PM
shildebrand
Occasional Contributor

Hi everyone,

I'm trying to piece this process together, but can anyone point me in the direction on how to publish a python script tool to ArcGIS Server as a geoprocessing service for the purpose of using it within the geoprocessing widget in ArcGIS Web App Builder?  The script tool runs successfully within Pro, but ideally I would like to use it within an existing Web App Builder application. The script tool uses an input polygon layer, which has a URL link to a pdf document for each polygon record.  Within ArcGIS Pro and after selecting polygons, the tool will output the pdf documents to a specified output folder (technically an input parameter).  Assuming that this tool can be published as a geoprocessing service, how would the user select polygons within the web app builder application or geoprocessing widget?  Below is the python code for the for the tool as well as a snip of the tool in ArcGIS Pro and a list of its parameters.  Any help or guidance on this subject would be greatly appreciated!

import arcpy
import os
import requests

fc = arcpy.GetParameterAsText(0)
dest_path = arcpy.GetParameterAsText(1)
print(fc)
cursor = arcpy.SearchCursor(fc)
with arcpy.da.SearchCursor(fc, ['LINK']) as cursor:
    for row in cursor:
        print("Downloading: " + row[0])
        response = requests.get(row[0])
        outputFile = row[0].split("/")[5]
        print(outputFile)
        with open(dest_path + '\\' + outputFile, 'wb') as f:
            print(f)
            f.write(response.content)
del cursor

 

shildebrand_0-1699910933550.png

shildebrand_1-1699910975338.png

 

 

0 Kudos
1 Reply
mody_buchbinder
Occasional Contributor III

Hi

 

You need to publish the tool to the server to make it gp service.

You have some issue with such a script as a service.

Does the server (and the user that runs it) have access to the fc and dest_path?

Using gp services need some thinking about access rights and multiple requests from different users

0 Kudos