How to execute an Iron Python script on loading of a cached analysis in TIBCO Spotfire Web Player

How to execute an Iron Python script on loading of a cached analysis in TIBCO Spotfire Web Player

book

Article ID: KB0075389

calendar_today

Updated On:

Products Versions
Spotfire Web Player All Versions

Description

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.

Issue/Introduction

This article outlines the limitations and the workarounds that can be used to make sure that the IronPython scripts are executed on opening an cached analysis by an end user

Resolution

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: Attached is the "ScheduledAnalysis_OnLoad.dxp" along with csv format data showing both the approaches

3. Custom DateTime Data Function for TIBCO Spotfire:

The main goal of the Custom DateTime Data Function for TIBCO Spotfire® is to enable the running of IronPython scripts on Analysis Open, Filter and Marking changes. The Custom DataTime Data Function allows one to trigger IronPython scripts without having to use a TERR/statistical Data Function for only that purpose.

Additional Information

KB: How to execute an IronPython script on initial load of an analysis using Data Functions Doc: Configuring TIBCO Spotfire to use TIBCO Spotfire Statistics Services KB 000033036 JavaScript triggering an IronPython Script on load of analysis does not execute In Automation Services Wiki Article: Custom DateTime Data Function for TIBCO Spotfire®

Attachments

How to execute an Iron Python script on loading of a cached analysis in TIBCO Spotfire Web Player get_app
How to execute an Iron Python script on loading of a cached analysis in TIBCO Spotfire Web Player get_app