Jump to content
  • How to set date RangeFilter using IronPython Script in Spotfire®


    The following IronPython code shows how to set a RangeFilter that is a Date using an IronPython script.  In the code, start and end year, month, day, hour and minute are all variables that can be passed in.  These values could be hardcoded into the script as well.

    Introduction

    The following IronPython code shows how to set a RangeFilter that is a Date using an IronPython script.  In the code, start and end year, month, day, hour and minute are all variables that can be passed in.  These values could be hardcoded into the script as well.

    Code sample

    # Copyright © 2017. TIBCO Software Inc.
    # Licensed under TIBCO BSD-style license.
    
    #####################
    ## setDateFilter
    ##
    ## This script changes a range date filter to a given
    ## range.  
    ##
    ##  INPUTS:
    ##
    ##    filterSchemeName
    ##     - Type: String
    ##         - name of filtering scheme in which to modify
    ##           filter
    ##
    ##    columnName
    ##     - Type: String
    ##         - name of column to filter
    ##
    ##    startYear
    ##     - Type: Integer
    ##         - start year to set the filter range
    ##
    ##    startMonth
    ##     - Type: Integer
    ##         - start month to set the filter range
    ##
    ##    startDay
    ##     - Type: Integer
    ##         - start day of month to set the filter range
    ##
    ##    startHour
    ##     - Type: Integer
    ##         - start hour to set the filter range
    ##
    ##    startMinute
    ##     - Type: Integer
    ##         - start minute to set the filter range
    ##
    ##    endYear
    ##     - Type: Integer
    ##         - end year to set the filter range
    ##
    ##    endMonth
    ##     - Type: Integer
    ##         - end month to set the filter range
    ##
    ##    endDay
    ##     - Type: Integer
    ##         - end day of month to set the filter range
    ##
    ##    endHour
    ##     - Type: Integer
    ##         - end hour to set the filter range
    ##
    ##    endMinute
    ##     - Type: Integer
    ##         - end minute to set the filter range
    ##
    ##    dataTable
    ##     - Type: DataTable
    ##         - data table that contains the column name to filter
    ##
    #####################
    
    from Spotfire.Dxp.Application.Filters import *
    from Spotfire.Dxp.Application.Visuals import *
    
    from Spotfire.Dxp.Application.Filters import ValueRange
    from System import DateTime
    
    #Get the active page and filterPanel
    filterPanel
     = Application.Document.ActivePageReference.FilterPanel
    
    #Get reference for FilteringScheme used for your filter
    for fs in Document.FilteringSchemes:
        ## find filterScheme and filter
        if fs.FilteringSelectionReference.Name
           == filterSchemeName: 
            filterCollection = fs[dataTable]
            filter = filterCollection[columnName]
            dateFilter = filter.As[RangeFilter]()
            dateFilter.ValueRange
             = ValueRange( DateTime( startYear,
                                     startMonth,
                                     startDay,
                                     startHour,
                                     startMinute,0,0,0 ),
                           DateTime( endYear,
                                     endMonth,
                                     endDay,
                                     endHour,
                                     endMinute,0,0,0 )
               )
     

    References

     

    License:  TIBCO BSD-Style License

    Back to IronPython Scripting in Spotfire Examples:  https://community.spotfire.com/s/article/IronPython-Scripting-in-Spotfire


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...