Jump to content

How to write selected filter values into separate manually created/automatic document properties


Nagendra babu

Recommended Posts

I have a script that adds all the selected values in a filter to one particular document property but I need to capture selected values in separate document properties, for example if I select 3 study Id's in the filter then it could capture it in study1, study2 and study3 respectively

below is the script i'm using currently.

from Spotfire.Dxp.Application.Filters import ListBoxFilter

import re

myDataTable=Application.Document.Data.Tables["Study_Data_Table"]   

filt= Document.FilteringSchemes[0][myDataTable][myDataTable.Columns["study_id"]].As[ListBoxFilter]()

for i in filt.SelectedValues:

val=Document.Properties["Study1"]

if val!="":

val=val+", "+i

else:

val=i

Document.Properties["Study1"]=val

print Document.Properties["Study1"]

Thanks in advance

Link to comment
Share on other sites

Try this script. Note that if all the study ids have been selected, this will need to be modified as the selected filter will be equal to "(All)", so no Study properties will be created.

I added a function to remove previously defined Study document properties, so that if a study id is deselected, it does not linger.

I am also assuming the study ids are of type String. If not, change DataType.String to something else.

This script should create as many document properties with name Study followed by an integer, as selected in filter for that column.

from Spotfire.Dxp.Application.Filters import ListBoxFilterfrom Spotfire.Dxp.Data import * import re # Unchanging parametersproperty_base_name = "Study" property_attributes = DataProperty.DefaultAttributes  # --------------------------------------------------------# Function to create new document property (if it does not already exist)def createDocumentProperty(property_name): new_property = DataProperty.CreateCustomPrototype(property_name, DataType.String, property_attributes) try: Document.Data.Properties.AddProperty(DataPropertyClass.Document, new_property) except: pass return None # Function to delete all existing Study propertiesdef deleteExistingProperties(): current_properties = Document.Properties  match_pattern ='^'+property_base_name +'\d+$' matched_properties=[] for cc in current_properties: test_match = re.findall(match_pattern,cc.Name) if len(test_match)>0: matched_properties.append(test_match[0]) for property_name in matched_properties: try: DataPropertyRegistry.RemoveProperty(Document.Data.Properties, DataPropertyClass.Document, property_name) except: pass return None # --------------------------------------------------------# Main codemyDataTable=Application.Document.Data.Tables["your table name"]  filt= Document.FilteringSchemes[0][myDataTable][myDataTable.Columns["your column name"]].As[ListBoxFilter]() deleteExistingProperties() k=1for i in filt.SelectedValues: property_name=property_base_name+str(k) createDocumentProperty(property_name) Document.Properties[property_name] = i k=k+1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...