How to execute an IronPython script on Filter or Marking change in Spotfire

How to execute an IronPython script on Filter or Marking change in Spotfire

book

Article ID: KB0070680

calendar_today

Updated On:

Products Versions
Spotfire Analyst All Versions

Description

Out of the box, it is not possible to execute an IronPython script when Filter or Marking changes. However, we can use Data Functions and Document Properties to achieve this. Document Properties can trigger IronPython scripts when their value changes. We will leverage this feature. High level and detailed steps are described below.

Issue/Introduction

How to execute an IronPython script on Filter or Marking change.

Resolution

High level steps:
  1. Create a dummy data function that runs when a filter changes.
  2. Associate the output value of this data function to a document property.
  3. Associate the IronPythonscript to this Document Property so it will be triggered when the document property changes.

Detailed steps:
  1. Edit >> Data Function Properties
    1. Click on "Register New"
    2. Name: triggerOnFilterChange
    3. Type: R Script - TIBCO Enterprise Runtime for R
    4. Description: Data function to pass value of x to y and current time to z
    5. Script: (#Here we are just passing the value ofto y, and then current time to z) 
      This way we ensure that the function is triggered when x, which is based on Filter, changes
      y <- x
      z <- Sys.time()
    6. Input Parameters >> Add >> x, Allowed Data Types: Integer
    7. Output Parameters >> Add >> y and z
  2. Run
  3. Edit Parameters
    1. Check the "Refresh Function Automatically" checkbox
    2. Input  #Input will come from the filter/marking. Make changes in the expression as needed.
      1. Input Handler: Expression
      2. Data Table: Your data table
      3. Expression: Count([Your table].[Column of choice])
      4. Limit By: Filtering scheme  #Choose marking if you want to trigger script based on Marking
    3. Output
    4. Select y
      1. Output Handler: Document Property
      2. New, DocProp1
    5. Select z
      1. Output Handler: Document Property
      2. New, DocProp2
  4. Ok
  5. Close  #Save to Library if you wish to
  6. Edit >> Document Properties >> Properties
    1. Select DocProp2
    2. Script >> Execute the script selected below
    3. Select the existing IronPython script, or click New to create a new IronPython script, that you would like to execute on filter/marking change, and click OK.

Note: for this solution to work in the Web Player/web clients, you need to have a TERR Service available. An alternative solution, that does not have that requirement, could be to use the Custom DateTime Data Function for Spotfire, which is available for download from the Community. For more information about that, see https://community.spotfire.com/articles/spotfire/custom-datetime-data-function-for-spotfire/

Additional Information

Doc: Spotfire Analyst User's Guide > How to Use Data Functions: Doc: Spotfire Analyst User's Guide > Details on Script – Act on Property Change: