Jump to content

How to add error handling to IronPython ListBox filter

Brittany Wiechelman

Recommended Posts

I have a multi-line textbox that users enter their list of values into, with each value separate on a new line. If one value is not found in the data set, then it won't even filter for any of the values that are found. Currently the code throws a generic error "One or more values is not found in the dataset". I want to tell the user what value was not found, and continue to filter for the values that were found.I think I have to set a Document Property for ValuesNotFound and display it, but unsure how to get the ValuesNotFound output.


Code below:

import Spotfire.Dxp.Application.Filters as filters

import Spotfire.Dxp.Application.Filters.ListBoxFilter

from Spotfire.Dxp.Application.Filters import FilterTypeIdentifiers

from Spotfire.Dxp.Data import DataPropertyClass

from System import String

Document.Properties["listFilterMessage"] = "Status: filtering..."

myPanel = Document.ActivePageReference.FilterPanel

myFilter= myPanel.TableGroups[2].GetFilter("part_number")

lbFilter = myFilter.FilterReference.As[filters.ListBoxFilter]()


strVals = Document.Properties["ListParts"]

if strVals!=String.Empty:



lbList = filter(len, lbList)


Document.Properties["listFilterMessage"] = "Status: filtered"

print("Status: filtered")



Document.Properties["listFilterMessage"] = "Error: at least one part number may not be in dataset"

print("filter failed: at least one part number may not be in dataset")



Link to comment
Share on other sites

You can use the below script as a reference to search if a given value exists or not and then set the filtering based on the valid values

import System.String as String

from Spotfire.Dxp.Application import Filters as filters


myPanel = Document.ActivePageReference.FilterPanel

myFilter = myPanel.TableGroups[0].GetFilter("Region")

listboxFilter = myFilter.FilterReference.As[filters.ListBoxFilter]()

#get the value from input field




print userInput



print "failed"



#create a list for setting listbox filter



#get the column reference to search for




#read the column values and check if they are in userinput

for columnValue in columnValuesCollection:

if columnValue.ValidValue in userInput:

# if valid exists then add it to the filtering list




#set ListBoxFilter with the values




Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...