I would like to add a parameter as value table with one of the fields being a value list. The value table consist of 3 columns, namely "table","field","description", whereas "field" is a value list. The values of the value list shall depend on the input "table, thus change with each new entry. E.g. adding a table xyz to the value list should lead to a list of fields which can than be selected.
My code for now:
def getParameterInfo(self): in_tables = arcpy.Parameter( displayName = "test", name = "test", datatype = "GPValueTable", parameterType = "Optional", direction = "Input") in_tables.columns = [["DETable", "table"],["GPString","field"],["GPString","description"]] in_tables.filters.type = 'ValueList' in_tables.filters.list = ["<marker spalte>"] #dummy list which is updated in updateParamters ... def updateParameters(self, parameters): if parameters.value and parameters.altered: fields_list = [field.name for field in arcpy.Describe(parameters.value).fields] parameters.filters.list = fields_list #update of dummy list
This actually works but I always get the field list of the very first entry. I thought about using len in order to always get the last entry (which is a bit more useable but still not satisfying). What I would prefer is the identification of the selected row in order to dynamically update the value list with the related field names.
Is there a way to do that?
The problem with my
parameters.value solution is, that it is not working if the any of the other tables has other fields than the first one. the problem when working with len() is that an error occurs if one of the former selected fields does not exist in the last field list. Thus I changed my updateParameters method.
if parameters.value and parameters.altered: all_tables_list = parameters.value number_of_tables = len(all_tables_list) i = 0 fields_list_tmp =  for in_table in all_tables_list: fields_list_tmp.append([field.name for field in arcpy.Describe(parameters.value[i]).fields]) i += 1 fields_list = list(set([item for sublist in fields_list_tmp for item in sublist])) parameters.filters.list = fields_list
which basically creates a list with all existing fields in all selected tables.