Michael Kalada 2 Posted March 26, 2020 Share Posted March 26, 2020 I have this script which gives the selected filter values, but they come in a vertical list and only write the last value to document property from Spotfire.Dxp.Application.Filters import ListBoxFilter #get a reference to a listbox filt=Document.FilteringSchemes[0][myDataTable][myDataTable.Columns["symbol"]].As[ListBoxFilter]() #to get the active filtering reference: #filt = Document.FilteringSchemes[Document.ActiveFilteringSelectionReference][myDataTable][MyDataTable.Columns["symbol"]].As[ListBoxFilter]() #loop selected values for value in filt.SelectedValues: print value SAMPLE OUTPUT: xx YY ZZ And this script which writes all available filter values in a nice string from Spotfire.Dxp.Application.Filters import * from Spotfire.Dxp.Data import * filteringScheme = Document.FilteringSchemes[0] dataTable = Document.ActiveDataTableReference filterCollection = filteringScheme[dataTable] filter = filterCollection['Business Unit'] Document.Properties["BUSINESSUNIT"] = filter.ToString() SAMPLE OUTPUT: (XX, YY, ZZ) but im having a heck of a time trying to get selected filter values into a nice string that can be set as document property Link to comment Share on other sites More sharing options...
Shashank Gurnalkar Posted March 27, 2020 Share Posted March 27, 2020 Define a List of type String. from System.Collections.Generic import List from Spotfire.Dxp.Data import * list_data = List [str]();Append the filtered value in the list inforloop. list_data.Add(value) If there are repeated values, you can use the 'set' function to get unique values. Use the 'join' function as shown to get the required string in a document property. # Get only unique values valData = List [str](set(list_data)) # Store in a document property yourVariableName = ', '.join(valData) Document.Properties["yourDocumentPropertyControl"] = yourVariableName Link to comment Share on other sites More sharing options...
Shandilya Peddi Posted March 27, 2020 Share Posted March 27, 2020 A similar approach for i in filt.SelectedValues:: val=Document.Properties["test"] if val!="": val=val+", "+i else: val=i Document.Properties["test"]=val Link to comment Share on other sites More sharing options...
Michael Kalada 2 Posted March 27, 2020 Author Share Posted March 27, 2020 Thanks for the hint. The final script which writes selected filter values to a document property is below. It writes them like ('PA', 'NJ', 'NY') so the document property can be used in an "in" expression. Script paramater is a myDataTable which is a Data Table parameter. The script writes the selected values for the list box filter on column [state] to document property "StateFilterSelectedValues" from Spotfire.Dxp.Application.Filters import ListBoxFilter from System.Collections.Generic import List from Spotfire.Dxp.Data import * list_data = List [str](); valData = List [str](set(list_data)) #get a reference to a listbox filt = Document.FilteringSchemes[Document.ActiveFilteringSelectionReference][myDataTable][myDataTable.Columns["State"]].As[ListBoxFilter]() #loop selected values for value in filt.SelectedValues: list_data.Add(value) print str(list_data).replace("List[str]","").replace("[","").replace("]","") Document.Properties["StateFilterSelectedValues"] = str(list_data).replace("List[str]","").replace("[","").replace("]","") Link to comment Share on other sites More sharing options...
Sharmilapriya Mohanasundaram Posted June 15, 2023 Share Posted June 15, 2023 I get the following error when I try to execute this script: Script: from Spotfire.Dxp.Application.Filters import ListBoxFilterfrom System.Collections.Generic import Listfrom Spotfire.Dxp.Data import *list_data = List [str]();valData = List [str](set(list_data))#get a reference to a listboxfilt = Document.FilteringSchemes[Document.ActiveFilteringSelectionReference][myDataTable][myDataTable.Columns["facility"]].As[ListBoxFilter]()#loop selected valuesfor value in filt.SelectedValues: list_data.Add(value)print str(list_data).replace("List[str]","").replace("[","").replace("]","")Document.Properties["StateFilterSelectedValues"] = str(list_data).replace("List[str]","").replace("[","").replace("]","")Error:Traceback (most recent call last): File "<string>", line 13, in <module>AttributeError: 'NoneType' object has no attribute 'SelectedValues'How do I resolve this? @SCRIBE System User Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now