Automatically applying one filtering schema changes to another schema
By:
Last updated:
2:41pm Nov 28, 2018

Introduction

Suppose You have two filtering schemas FS1 and FS2 and You added a filter from FS1 to the text area and selected a particular value. The following example is an iron python script which can set same value to filter schema FS2.

Example

Before creating this script you should create an R  data function for store selected value from the text area to a document property and assign script.

R Data Function

 

Input Parameter

 

Output Parameter

from Spotfire.Dxp.Application.Filters import *

from Spotfire.Dxp.Application.Visuals import VisualContent
from System import Guid
SelectedList=[] #Array declare
flag =0
if Document.Properties["Shipmode"]!=None:  #If no Item selected we dont neeed to update the list
	SelectedList =Document.Properties["Shipmode"].split(',')
	flag=1
print SelectedList
String=''
print SelectedList
for items in SelectedList:  # Remove the extra space(Document property contains an extra space #when we select multiple values)
	String= String+items.strip()+","
print String
String= String[:-1] 
mylist=[]
mylist=String.split(',')
print mylist
#Get the active page and filterPanel
page = Application.Document.ActivePageReference
filterPanel = page.FilterPanel

#Get reference for FilteringScheme used for your filter
for fs in Document.FilteringSchemes:
    if fs.FilteringSelectionReference.Name == "FS2": #Second filter schema
        filterPanel.FilteringSchemeReference = fs

#Let's find "Col_LBFilter" filter and read the selected Values
#This example uses a listbox filter, you may use any.
filterPanel.InteractiveSearchPattern = "Ship Mode"  # Give the column name
for filter in filterPanel.FiltersMatchingSearchPattern:
	if filter.FilterReference.Name == "Ship Mode": #check the given column is exist in filterpanel
		lbFilter = filter.FilterReference.As[ListBoxFilter]()
		print lbFilter.SelectedValues
		lbFilter.Reset()  #Reset filter
		lbFilter.IncludeAllValues = False
		print mylist
		if SelectedList!=None and flag==1: #If no Item selected we dont neeed to update the filter
			#print "sanandh"
			#print flag
			lbFilter.SetSelection(mylist)

 

Introduction

API Reference: Spotfire Analyst

API Reference: ListBoxFilter. SetSelection

Feedback (2)

Thanks Ankita

Sanandh 6:11am May. 28, 2018

Following Script is for List Box:

 

from Spotfire.Dxp.Application.Filters import *

from Spotfire.Dxp.Application.Visuals import VisualContent
from System import Guid
SelectedList = Document.Properties["FilteredShipModes"].split(', ')
print SelectedList

page = Application.Document.ActivePageReference
filterPanel = page.FilterPanel

for fs in Document.FilteringSchemes:
    if fs.FilteringSelectionReference.Name == "Period 2": #Second filter schema
        filterPanel.FilteringSchemeReference = fs

filterPanel.InteractiveSearchPattern = "Ship Mode"  # Give the column name
for filter in filterPanel.FiltersMatchingSearchPattern:
    if filter.FilterReference.Name == "Ship Mode": #check the given column is exist in filterpanel
        lbFilter = filter.FilterReference.As[ListBoxFilter]()
        print lbFilter.SelectedValues
        lbFilter.Reset()  #Reset filter
        lbFilter.IncludeAllValues = False
        lbFilter.SetSelection(SelectedList)
        print lbFilter

ankitajaiswal432 3:57am May. 28, 2018