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:
I have created the python script and I am using the validation code to create the drop down lists, something like this:
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
self.params.value = None
"""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.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:
But this will generate an error in the tool as it seems incapable of dealing with empty / null values.
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.