0

I have a layer of polygons representing land parcels, each of these has a number that identifies it as part of an application, I want the user to be able to select one of these polygons, submit it to a tool and have it return all of the other polygons with a matching application number. It currently runs fine in ArcGIS Pro, but not in web app builder.

This is a snippet of the code that runs in ArcGIS Pro, but I can't get to work as a geoprocessing service within Web App Builder

It basically takes a layer with a selection, determines a value with a search cursor and then uses that value to make a selection based on it to capture all polygons that had that value. This is meant to be used for a data validation sequence, so users aren't manually entering the polygon ID number.

import arcpy

# Get parameters for input
# Existing DID Layer
inputpolygons = arcpy.GetParameterAsText(0)

#tableview="didofinterest"
arcpy.AddMessage("Executing...")

# Determine if a selection has been made.  If not, report error.
desc=arcpy.GetCount_management(inputpolygons)
if int(desc[0])>0:
    arcpy.AddMessage("Selection found.")
    arcpy.AddMessage(f"Found {str(desc[0])} Selections, choosing first")

    # Get the first DISP Num of the input table (first of the selection)
    with arcpy.da.SearchCursor(inputpolygons,["DISP_NUM"]) as cursor:
        for row in cursor:
            polynum=row[0]
            arcpy.AddMessage(f"Getting {polynum} from {inputpolygons}")
            break

    # Build where clause
    whereclause = """ DISP_NUM = '%s' """ % polynum

    # Make a selection.
    selected_polygons=arcpy.management.SelectLayerByAttribute(inputpolygons,"NEW_SELECTION",whereclause)

As a script tool it has a single input parameter which is currently set as a Feature Layer type.

When I publish to Portal, the tool has upload capabilities, Asynchronous execution and the message level is set to Info. The input parameter is set as user defined.

When I add the widget into web app builder the single input layer is set to Choose from map.

Running it as a widget causes the app to execute and its output to post to the output screen for a split second and then it clears it, making it nearly impossible to see what is happening. I have managed to determine the geoprocessing widget is not honoring the selection in the web app layer.

6
  • There's no need to include your whole code, just a test script that has enough of your code in it that it fails in the same way when you try to take it through to ArcGIS Web AppBuilder.
    – PolyGeo
    Commented Mar 9, 2023 at 3:03
  • The code runs. That is the problem. I don't know what is failing or where because I can't see any of the output. Any code I would share will work fine, cause I can run it in ArcGIS pro just fine. Commented Mar 9, 2023 at 3:34
  • Look at or get your GIS admin to look at the ArcGIS Server Manager Logs
    – user2856
    Commented Mar 9, 2023 at 6:00
  • To attract a potential answerer to your question, it is best to include a full description of how your problem can be reproduced. Since there is code involved in your workflow providing test code saves a potential answerer having to guess what might be in yours.
    – PolyGeo
    Commented Mar 9, 2023 at 7:45
  • I've had code that works as a Pro tool but fails in Server/Portal GP services. Adding a small example that demonstrates the issue and shows your input and output parameters will help you get an answer.
    – user2856
    Commented Mar 9, 2023 at 9:21

1 Answer 1

0

There is a very loose coupling between a GP Service and the layers found within a Webmap. Inside ArcGIS Pro, the coupling is very tight. This is a very high-level way of saying it doesn't work in the same way: The GP Service isn't going to put a selection on the layers in your webmap.

In a webapp, or in your case of WebApp Builder, you have 2 services. These services are not using the same data. They may appear to be, but they aren't. Or at least they aren't in the sense that what one service does will be available to the other service. When your GP Service puts a selection on a layer (and yes, the GP Service can be making use of layers internal to itself), that selection is not applied to the data in the map service. It's a selection unique to the single job execution of the GP Service. You'd need to return the output, either as a MapImage Layer, or the actual selected features and have the web app draw them. As you only mention you make use of a single input parameter, it sounds as if your tool has no outputs. In that case, the GP Service is never "returning" anything, thus the web app has nothing to draw.

I wrote this blog a few years ago and it covers some of the same concepts. While it doesn't get into the same details here as the difference in layer sources, it may further your understanding of this task.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.