Empty values in drop down list for a geoprocessing service

1269
2
09-07-2018 08:50 AM
GiacomoFavaron
New Contributor III

I cannot find a solution to this.

I have a huge feature class with millions of records and I need to be able to filter it using a number of fields from its attribute table. To create a list of options for the input parameters to the filter I have created a number of tables containing all the available options from the main feature class for example for the field called CityName in the feature class I have a different table showing all the unique values for that field, for example:

OIDCityName
1New York
2

Paris

3Rome
4etc..

I have created the python script and I am using the validation code to create the drop down lists, something like this:

def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""

self.params[0].value = None

return

def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""

Cities = "Database Connections\\Prod (LHRDB8511) GISadmin.sde\\MyDB.dbo.Portfolio_Cities"
rows1 = arcpy.SearchCursor(Cities)
self.params[0].filter.list = sorted(list(set(row.getValue('CityName') for row in rows1)))

The input parameter is however optional, meaning that the user can leave it blank and here lies the problem because despite the tool working very well in ArcGIS Desktop and Pro, once the tool is published as a geoprocessing service you don't have the option to leave it blank anymore but you are forced to select one of the values, like one of the cities in the example, or at least this is what happens in the Geoprocessing widget for WAB.

I have tried to add an empty value in the tables used for the filtering, like:

IDCityName
1
2New York
3

Paris

4Rome
5etc..

But this will generate an error in the tool as it seems incapable of dealing with empty / null values. 

ERROR 
updateParameters Execution Error: Runtime error Traceback (most recent call last): File "E:\GIS Data\TOOLS\Custom Filter\CustomFilterPortfolio.tbx#DropDown22.UpdateParameters.py", line 4, in File "E:\GIS Data\TOOLS\Custom Filter\CustomFilterPortfolio.tbx#DropDown22.UpdateParameters.py", line 34, in updateParameters File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\arcobjects\_base.py", line 89, in _set return setattr(self._arc_object, attr_name, cval(val)) ValueError: FilterObject: illegal list value

My final aim is to deploy the geoprocessing service via Web AppBuilder. I have tried the Filter widget already but it's breaking, just too many values to retrieve dynamically.

Is there a solution to this problem? Is there another way to deal with null values in the validations script?

Thank you all.

Giacomo

0 Kudos
2 Replies
YoavAbadi
New Contributor II

Hi,

Not sure I've understand you correctly, if you are trying to filter out null values, you can do that with sevral ways:

1. inside the SearchCursor itself, with a where_clause sql expression:

wc = '{} IS NOT NULL'.format('CityName')‍
rows1 = arcpy.SearchCursor(Cities, 'CityName', where_clause=wc)‍‍‍‍
# The Rest of your code

Alternatively, you could filter the null values while iterating:

with arcpy.da.SearchCursor(Cities, 'CityName') as cursor:
    for row in cursor:
        if row[0] is not None:
            # The Rest of your code

Hope it helps,

Yoav.

GiacomoFavaron
New Contributor III

Hi Yoav,

What I am trying to do is the very opposite. I want to have a null value in the dropdown list

0 Kudos