Add rows from varying files depending on document property selection

Hi

I would like to add rows containing some reference information but the user should be able to select which reference to use with a document property. So I have a drop down list which contains various names of available references but then I'm pretty much stuck. I have the vague feeling that I will need to use IronPython (something I'm not familiar with) to pull this off but I'm not sure. So far I only found some code how to add columns and wouldn't even be sure how to change that such that it uses the value of my document property. So here's the code I found on the web at http://stn.spotfire.com/stn/Configure/ScriptingIntroduction.aspx:

# This script adds columns from an sbdf file to a data table  
# in the current document.  
#   
# Four arguments are expected:  
#   table - The data table in the current document  
#           that columns will be added to.  
#   path - The path to the sbdf file with columns to add.  
#   ColumnNameInTable - A column in the data table.  
#   ColumnNameInFile - A matching column in the sbdf file.  
# The columns are used to join new data to the current data.  

from Spotfire.Dxp.Data.Import import SbdfFileDataSource  
from Spotfire.Dxp.Data import AddColumnsSettings, JoinType, DataColumnSignature, DataType  

# Create the join condition map. The column with the name  
# specified in ColumnNameInTable from the current data table   
# will be joined with ColumnNameInFile in the sbdf file.  

columnInTable = DataColumnSignature(table.Columns[ColumnNameInTable])  
columnInFile = DataColumnSignature(ColumnNameInFile, DataType.String)  
joinConditionMap = {columnInTable : columnInFile}  

ignoredCols = [ ]  
settings = AddColumnsSettings( joinConditionMap, JoinType.InnerJoin, ignoredCols)  
ds = SbdfFileDataSource(path)  
table.AddColumns(ds, settings) 

I was going to insert a an action control below my drop-down list which runs a similar script to read lines from the selected source file (I would need to add a fixed path before the file name) and insert the data as new rows matching certain column names. Ideally the script inserts the rows as soon as the user selects a value from the drop down such that no additional action control for starting the script would be required. How can this be acchieved?

Bonus question would be: could the source file also be a CSV file rather than an SDBF file?

Thanks a lot in advance,

Mark

(3) Answers

Login