0

Is it possible to create a new Filtering Scheme and set it to a page only using Iron Python? The reason why I am looking into that is because the Web Player currently does not allow us to create Filtering Schemes. I hope to achieve that by executing a script which will be triggered by a Document property change. The name of the filtering scheme will be passed from the JavaScript api my using SetDocumentProperty method.

The script below adds a new Filtering Scheme but I cannot select it from the Filtering Scheme menu in the Spotfire Analyst, it's nowhere to be seen. What am I missing?

from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application.Filters import *

Document.ActivePageReference.FilterPanel.Visible = True
# Add a new data filtering selection.
filterings = Document.Data.Filterings

filterings.Add("Test Filtering 1")

for f in filterings:
    print f.Name

enter image description here

I cannot see my newly added FilteringScheme after I ran the above script from the Filtering Scheme menu on the Analyst:

enter image description here

Georgi Koemdzhiev
  • 11,421
  • 18
  • 62
  • 126

1 Answers1

1

The issue here is that "filterings" is a variable that you created, not an alias for the filter list -- you filled it with the data in the existing filters, but updating filterings afterwards does not update the filters on the page itself.

Change the code to this:

from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application.Filters import *

Document.ActivePageReference.FilterPanel.Visible = True
# Add a new data filtering selection.
Document.Data.Filterings.Add("Test Filtering 1")
filterings = Document.Data.Filterings

for f in filterings:
    print f.Name
Chelsea
  • 491
  • 5
  • 8
  • Thank you for your suggestion. I have run your script: copied the script; went to Document Properties/Scripts; Added a new script and ran it; pressed OK (to close the window). Then went to Document Properties again and opened the "Filtering Schemes" tab but didn't see the new "Test Filtering 1" filtering scheme in the list there – Georgi Koemdzhiev Oct 04 '19 at 08:25
  • 1
    @GeorgiKoemdzhiev Interesting. It looks like that doesn't work if you run it directly in the Scripts tab; potentially because Filtering Schemes is considered "open"? After all, this is where you add or delete Filtering schemes, so it's plausible that it runs a hidden script to update filtering schemes to match when you close the window. It'll work if you put that script on a button, dropdownlist, input field, or something similar. – Chelsea Oct 04 '19 at 15:49
  • Oh, I see. I will try that instead. Thank you – Georgi Koemdzhiev Oct 07 '19 at 07:20