AnsweredAssumed Answered

Parameter Validation using SearchCursor

Question asked by JMossing on Nov 20, 2019
Latest reply on Nov 24, 2019 by rvburton

I am developing a script to Add, Delete, and Update rows within a table. The script basic function works well using InsertCursor and UpdateCursor. My questions or troubles come when I attempt to use script validation to auto populate some of the parameters.

 

When the users choose to Update a Row, they pick a country from a list. Then the validation prepoulates 5 parameters from the existing row in the table. I am using SearchCursor within script validation to auto populate those fields. That generally works well. 

 

The problem is the script validation never seems to stop. So after the user picks a country code, 5 parameters are populated in the tool dialog with data from the fields in the table. Ideally I would like the user to be able to type over those entries and then resubmit to the table for changes. However every time the user changes one of the parameters the script validation overwrites it with the original value from the table. Does anyone have any suggestions on how I can make the parameters populate with the field data in the table, and still allow the user to be able to manually change those parameters for update purposes?

 

Here is a code snippet:

if self.params[1].value == True or self.params[2].value == True:

  self.params[4].filter.list = [str(val) for val in sorted(set(row[0] for row in arcpy.da.SearchCursor(Table,Field)))] 

  wClause = "COUNTRY_CODE ='{}'".format(self.params[4].value)

  # SO FAR EVERYTHING WORKS FINE

  # HERE IS THE VALIDATION THAT USES SEARCHCURSOR AND IT WORKS

  if self.params[4].altered:

    values = next(arcpy.da.SearchCursor(Table, Fields, where_clause=wClause))

    self.params[5].value = values[0]

    self.params[6].value = values[1]

    self.params[7].value = values[2]

    self.params[8].value = values[3]

    self.params[9].value = values[4]

    self.params[10].value = values[5]

 

So after the searchcursor populates the params, how can i stop the validation and let the user manually edit those params?

Outcomes