Introduction
Note: In Spotfire® 10.3 the RefreshAsync method is obsolete. This example can be achieved much easier using the synchronous ReloadAllData method. See below.
Under some scenarios, it may be required to perform some action after a data table has completed to refresh or reload. In such cases, if you are refreshing the underlying data table via a Python script, then it is possible to take advantage of the RefreshAsync API callback function, introduced in Spotfire® version 7.0. You would need to add the action(s) to be performed in a second Python script. With the new API, you could check if the data table(s) have successfully completed refreshing and invoke your second Python script to be executed. Note that since the IronPython Runtime removes all "global" variables from memory when the script finishes to execute, it is important to ensure to add all global variables and types to the closure when writing the callback function.
Code Sample
Spotfire® 10.3 or later:
# Copyright © 2019. TIBCO Software Inc. Licensed under TIBCO BSD-style license. # Reload data table, linked and stored data Document.Data.Tables["yourTableName"].ReloadAllData() # Reload has finished. Perform action.
Spotfire® 10.2 or earlier:
# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. import clr from System.Collections.Generic import List, Dictionary from Spotfire.Dxp.Data import DataTable from Spotfire.Dxp.Application.Scripting import ScriptDefinition from Spotfire.Dxp.Framework.ApplicationModel import NotificationService # Notification service notify = Application.GetService[NotificationService]() # Get second script scriptDef = clr.Reference[ScriptDefinition]() Document.ScriptManager.TryGetScript("yourSecondScriptName", scriptDef) params = Dictionary[str, object]() # Refresh Callback function def execCallBack(exception, Document=Document, notify=notify, params=params, scriptDef=scriptDef): if not exception: # executes the script Document.ScriptManager.ExecuteScript(scriptDef.ScriptCode, params) else: notify.AddErrorNotification("Error refreshing table(s)","Error details",str(exception)) # Get/Add table(s) to refresh # Note that more than one table can be added to the List object. Repeat the Add() method if needed for multiple tables to refresh. Tbls = List[DataTable]() Tbls.Add(Document.Data.Tables['yourTableName']) # Refresh table (new 7.0 API) Document.Data.Tables.RefreshAsync(Tbls, execCallBack) ############################################# #Where 'yourSecondScriptName' and 'yourTableName' are respectively the name of your script and table.
References
-
API Reference: DataTableCollection. RefreshAsync Method (obsolete in 10.3)
License: TIBCO BSD-Style License
Recommended Comments
There are no comments to display.