Jump to content
We've recently updated our Privacy Statement, available here. ×
  • How to trigger an IronPython script on report load via a JavaScript in Spotfire®


    This example demonstrates how to invoke an IronPython script on load via a JavaScript script. Many a times the id of the IronPython Action control button is used in the JavaScript scripts. Sometimes these scripts fail on the Web Player as these id's are generated dynamically. It makes use of the "division ie div" tag so that the javascript stays "id" independant and works as expected on the Web Player.

    Introduction

    This example demonstrates how to invoke an IronPython script on Spotfire Document load via a JavaScript script. Many a times the id of the IronPython Action control button is used in JavaScript scripts. Sometimes, these scripts fail on the Web Player as these id's are generated dynamically. It makes use of the "division ie div" tag so that the javascript stays "id" independent and works as expected on the Web Player.

    In this example, we create an IronPython script which gets the current datetime and update a string document property mapped in a text area visualization. This IronPython script is triggered via a JavaScript which triggers on the JavaScript document.onload event.

    Important - the JavaScript script included in this example uses JQuery. Please read this article before proceeding further: https://community.spotfire.com/articles/spotfire/how-to-include-your-own-instances-of-jquery-and-jqueryui-in-text-areas/

    Steps

    1. Create a new dashboard loading a simple text file or data from clipboard.

    2. Create a new string label document property e.g. "StrDate"

    3. Add a new text area visualization.

    4. Insert a new IronPython script as below:

       import datetime 
       #Update the document property with the latest time 
       Document.Properties["StrDate"]=str(datetime.datetime.now())
       
    5. Edit the text area HTML, and surround the IronPython button control with a DIV tag. This will be used later in the JavaScript script to access the button and then click it.

      The text area html would look like:

      <DIV id=myNtnl>
      	<SpotfireControl id="ad2a931ba00b4414982fb6dc78d9114b" />
      </DIV>
      <br> 
      <br> 
      <P><SpotfireControl id="0a0a189dc4f940a0a00f4e4e9b29d9d8" /></P>
       

       

      ad2a931ba00b4414982fb6dc78d9114b - the Id of the IronPython action control (button).

      0a0a189dc4f940a0a00f4e4e9b29d9d8 - Id of the StrDate document label property control.

    6. Create new JavaScript script as shown here-

       $(document).ready(function() {
       	if(!document.readyFlag) {
          	$("#myBtnl .sf-element").trigger("click");
              document.readyFlag=true;    
      	} 
      });
       

      This JavaScript script should now be triggered only once on the document load event.

    7. Save the dashboard in the library and now every time this report is loaded in the Spotfire client or the Web Player the "StrDate" document property will be updated with the current time.

    Notes

    The JavaScript scripts you add to the text area will execute in the same environment as the JavaScript defined by Spotfire to implement all functionality in the text area and other Spotfire visualizations.

    Also, even though it may be technically possible to access elements outside what is exposed through the public API, such usage is strongly advised against. Spotfire provides no guarantee whatsoever of the correctness, usability or compatibility of the libraries in scope.

    Future versions of Spotfire are likely to include other, upgraded and or incompatible libraries. Thus if you use JQuery in a JavaScript it might result in an erroneous Text Area when the dxp file is opened in a future version of Spotfire.

    License:  TIBCO BSD-Style License

    Back to IronPython Scripting in Spotfire Examples


    Attachments

    Download attached file from Resources.
     

    trigger_python_onload_js.dxp


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...