I'm working in Tibco Spotfire and would like a way to update all of the data sources in an analysis. This can be done using the script described here: Spotfire - How to add a reload button
I've implemented like this:
# * * *
#
# Update tables based on:
# https://stackoverflow.com/questions/49997755/spotfire-how-to-add-a-reload-button
#
# * * *
import ctypes
from System.Collections.Generic import List, Dictionary
from Spotfire.Dxp.Data import DataTable
from System.Collections import ArrayList
ctypes.windll.user32.MessageBoxW(0, "About to refresh all data from databases...", "Data Update", 1)
tables = ArrayList()
tables.Add(Document.Data.Tables["raw_table_col_detail"])
tables.Add(Document.Data.Tables["age_group"])
Document.Data.Tables.Refresh(tables)
ctypes.windll.user32.MessageBoxW(0, "Done with update.", "Data Update", 1)
I would now like to implement this so that it will work for any analysis. How can I get a list of available tables and then iterate through the list (i.e. how can I do the above dynamically without having to specify the table names, "raw_table_col_detail", "age_group", etc.).
Depending on which version of Spotfire you're using, there are a couple of options as outlined here https://community.tibco.com/wiki/how-refresh-or-reload-data-using-ironpython-script-tibco-spotfire
You could iterate through them and refresh one at a time
import ctypes
ctypes.windll.user32.MessageBoxW(0, "About to refresh all data from databases...", "Data Update", 1)
for t in Document.Data.Tables:
t.Refresh()
ctypes.windll.user32.MessageBoxW(0, "Done with update.", "Data Update", 1)
Or you could push them to an array and refresh them together
import ctypes
from System.Collections import ArrayList
tables = ArrayList()
for t in Document.Data.Tables:
tables.Add(t)
ctypes.windll.user32.MessageBoxW(0, "About to refresh all data from databases...", "Data Update", 1)
Document.Data.Tables.Refresh(tables)
ctypes.windll.user32.MessageBoxW(0, "Done with update.", "Data Update", 1)