Select to view content in your preferred language

Using dynamic filter lists in Portal parameters

316
1
12-14-2023 02:33 AM
Fredrock
New Contributor

Hello, 

 

I want to have 2 dependant choice list in Geotreatment  widget WebAppBuilder in portal.

The 1st parameter is a list like [1, 2, 3, 4, 5].

The 2nd choice list has values that depend on the choice in the first parameter, the 3rd has values that depend on the choice of the 2nd.

It runs well ArcGis Pro. When I publish the tool, the lists of second and third parameters are frozen. Change the selected value on the first parameter doesn't change values in the second one, and the same for the 3rd parameter. When I want to publish the tool, I don't have any other choice than "Choice list" and "Constant value". When I select Choice list, I have the filtered values when running the tool. Same in portal after publishing.

 

How can I keep dynamic lists in Portal (widget Geotreatment in webappbuilder) for the 2nd and 3rd parameter?

 

code in tool validator : 

class ToolValidator:
# Class to add custom behavior and properties to the tool and tool parameters.

def __init__(self):
  # set self.params for use in other function
  self.params = arcpy.GetParameterInfo()

def initializeParameters(self):
  self.params[0].filter.list = ['R. BARA', 'R. CENTRE-OUEST', 'R. GRAND EST', 'R. HAUTS-DE-FRANCE', 'R. ILE-      DE-FRANCE', 'R. NORMANDIE', 'R. SUD-OUEST', 'R. SUD-PACA']
  # Set the dependencies for the output and its schema properties
  self.params[1].parameterDependencies = [0]
  self.params[2].parameterDependencies = [0, 1]
  return

def updateParameters(self):
  # Update params[1] with the choice of params[0]
  if self.params[0].valueAsText and self.params[0].altered:
    ceinput = r"Z:\Geoprocessing\Chalandises_ISDND_Gestion des flux\Chalandise ISDND.gdb\COP_Output"
    reg = set(row.getValue('Activité') for row in arcpy.SearchCursor(ceinput) if row.getValue('Région') in self.params[0].valueAsText)
    self.params[1].filter.list = sorted(reg)
    self.params[2].filter.list = [] # Réinitialiser le filtre du quatrième paramètre
  # Update params[2] with the choice of params[1] and params[0]
  if self.params[0].valueAsText and self.params[1].valueAsText and self.params[1].altered:
    ceinput = r"Z:\Geoprocessing\Chalandises_ISDND_Gestion des flux\Chalandise ISDND.gdb\COP_Output"
    listeCOP = []
    regions = self.params[0].valueAsText
    activities = self.params[1].valueAsText.split(";")
    for activ in activities:
      with arcpy.da.SearchCursor(ceinput, ['Région', 'Libellé_COP', 'Activité']) as cursor:
        for row in cursor:
          if row[2] == activ.replace('\'','') and self.params[0].valueAsText in row[0]:
            listeCOP.append(row[1])
  act = set(listeCOP)
  self.params[2].filter.list = sorted(act)
  return

0 Kudos
1 Reply
DonMorrison1
Occasional Contributor III

I haven't worked with publishing geoprocessing tools in a while but I'm quite sure that selection lists are baked in at publishing time.  Essentially I think the code in UpdateParameters is never called when run from the web.   Here is a similar post

0 Kudos