Product: TIBCO Spotfire®
How to execute an Iron Python script on loading of a cached analysis in TIBCO Spotfire Web Player
In general, IronPython scripts cannot be set to automatically execute when a report is opened, but instead must be manually triggered with an action control button/link or on a property change. One method to trigger the script to execute automatically is to use a data function, which executes when the analysis is opened to update a document property configured to execute the IronPython script on a property change. Another method is through the use of Javascript and HTML script. When an IronPython script is set to be executed on loading of an analysis using data functions, the same will be executed when the analysis is cached by the scheduled updates as well. However the IronPython script may not be executed when this cached analysis is loaded because Data function is set to trigger only if its input parameters change. If you would like to execute the IronPython script when the cached analysis is loaded on TIBCO Spotfire Web Player, you can use the below three workarounds,
1. Using Data Functions:
Define an Input Parameter that is based on a column from a data table which is reloaded for each user. Do (Edit > Data Table Properties > select the data table > Scheduled Updates tab > Check "Reload the following data for each user" for the data table) so that there is an update when the cached report is opened by the end user which will trigger the data function execution.For example:
Name: Update_CurrentDateTimeProperty
Script:
input output <- Sys.time()Input Parameter:
- Name: input
- Type: value
- Input: Expression: First([myDataTable].[myColumn])
Output parameter:
- Name: output
- Type: Value
- Output: Document property:CurrentDateTimeProperty
However if you select an table which takes time to reload then it may be time consuming. For this you may want to add a small data table and reload it for each user.
See KB 000020939 How to execute an IronPython script on initial load of an analysis using Data Functions for more details
2. Using HTML and JavaScript:
In this approach, you need to have action control button in a Text Area visualization and associate the IronPython script to it. In the HTML you can hide this button if needed and add a JavaScript as below which will be triggerred every time the analysis is loaded and executes a button click. Sample HTML and JavaScript would be as below,HTML:
<Span style="display:initial" id="myBtn"> <P><SpotfireControl id="0bd86d67c6414b15a9cb54aa3d7dff62" /></P> </span>The id here will correspond to the Button Action control
JavaScript:
$(document).ready(function() { if(!document.readyFlag) { $("#myBtn .sf-element ").trigger("click"); document.readyFlag=true; } })Here readyFlag is a runtime flag used to click the button.Once the button is clicked the readyFlag is set to true, so the java script would not be re-executed.
Note:
- The Javascript above would not be executed when scheduled updates is caching the analysis but only executed when the analysis is opened on TIBCO Spotfire Web Player
- This KB article is related to the TIBCO Spotfire Web Player only. If you need the IronPython script to execute on load of an analysis when using Automation Services, please see the resolution in KB 000033036 JavaScript triggering an IronPython Script on load of analysis does not execute In Automation Services
Comments
0 comments
Article is closed for comments.