Search code examples
ironpythonspotfire

Why can I not cast my filter as listboxfilter in ironpython?


The result of my .AsListBoxFilter is None, as per the error message AttributeError: 'NoneType' object has no attribute 'SetValues'. I see no reason why this would fail, since my data is categorical.

for vis in visuals:
    dt = Document.Data.Tables["abcddata"]
    filter = Document.FilteringSchemes.DefaultFilteringSchemeReference[dt]["JNJ_BATCH_ID"]
    lb = filter.As[ListBoxFilter]()
    tofilter = ["61568283", "61568290"]
    lb.SetValues(tofilter)

Solution

  • There are a few extra statements needed, and indeed the function SetValues does not exist. I replaced it with SetSelection. You need to set IncludeAllValues to False before, otherwise it does not select.

    I removed the loop through the visuals as setting the filter did not use visuals.

    To make answering easier, please include the imports and variable settings in a sample script. This worked for me (with my sample data):

    import Spotfire.Dxp.Data
    import Spotfire.Dxp.Application.Filters
    from Spotfire.Dxp.Application.Filters import ListBoxFilter,FilterTypeIdentifiers
    
    dt = Document.Data.Tables["abcddata"]
    filter = Document.FilteringSchemes.DefaultFilteringSchemeReference[dt]["JNJ_BATCH_ID"]
    filter.TypeId = FilterTypeIdentifiers.ListBoxFilter
    lb = filter.As[ListBoxFilter]()
    tofilter = ["61568283", "61568290"]
    lb.IncludeAllValues=False
    lb.SetSelection(tofilter)