Using Script Controls to automate tasks in TIBCO Spotfire and TIBCO Spotfire Web Player


The TIBCO Spotfire SDK allows developers to do three things: Automate, Extend, and Integrate. Automations allow us to automate common tasks and idioms inside TIBCO Spotfire Professional.  Extensions allow us to create extensions to the Spotfire platform, like new visualizations, new calculations, new panels, etc'Integrations allow us to integrate Spotfire Professional and/or the Spotfire Web Player into other applications and components.


In TIBCO Spotfire version 3.1, TIBCO introduces the concept of Script Controls. Scripts Controls provide the ability to add IronPython scripts into a Text Area inside a Spotfire Analysis file. The script has access to the full Client API (from the SDK), and its goal is to perform common automation tasks. Its purpose is not to do or replace any extensions or integrations.   So, the next question is for automation, should I use the full SDK or should I use the Script Controls? There is some overlap, but there are a couple of key differences. 

First, using the full SDK is for more powerful algorithms or automations which are meant to be used inside TIBCO Spotfire Professional or Enterprise Player only.  In these situations, you are usually displaying a dialog and adding capabilities to help out a Business Analyst or Author.  Using the Script Controls  is for when you want to do some lightweight automation, where you do not need a dialog, and you wish to have the solution work in all the TIBCO Spotfire Clients, including the Web Player. Therefore, the functionality created using the Script Controls typically will benefit the Business Author.

The second important difference between the full Client APIs from the SDK (using C#) and Script Controls is that full extensions built using our C# API are built in the Spotfire application itself. This means it can work across and be available for any Spotfire document.  Script Controls, on the other hand, are built and stored inside a specific document.  If you wish to use them in multiple documents, you need to copy the script into each one.

Let's look at a two use cases to highlight the difference between the C# APIs and Script Controls. Assume you want to create a tool that acts as a template selection tool, which will provide the user with two lists: first a list of data tables, and then another list of templates to choose from. The tool will allow the user to select values from each list box and load and configure the appropriate document in Spotfire.  For this, you would use the full C# API to build a custom tool, which includes a dialog. This solution will not work  in the Web Player, as these types of changes should be done in the Professional Client and the tool is targeted at Business Analysts and Authors.

Next , assume you created a document which includes a property control to define where to expose a vertical reference line in a Scatter Plot. You can have the user enter a number and have the reference line move to that location. But what if you wanted to allow the business user to toggle the reference line on or off? For this, properties will not work, but we can leverage Script Controls. 

So how do you build such a Script? First, you need to turn on editing in a Text Area, and then select the Insert Action Control icon.  On the resulting Action Control dialog, choose to create a new script.


 
Then , in the next dialog, give your Script  a name and enter the Script.


 

Once you are done, click OK, and you are ready to use your script.


 
For more information about Script Controls, including details of IronPython, how to use Properties as input and outputs to the Scripts, and best practices, please attend our 3.1 Delta Training or our dedicated course, Using Script Controls inside TIBCO Spotfire.