Details on New/Edit Script


It is possible to add your own custom actions using IronPython or JavaScript scripts. The options available in the New/Edit Script dialog will differ depending on whether you are creating a JavaScript or IronPython script.

The resulting action control for an IronPython script is launched from a text area, a graphical table, or a KPI chart. See Using Scripts in the Text Area and IronPython Example Scripts for more information.

JavaScript scripts are launched from a text area, and can be used to decorate elements and make them more interactive. JavaScript scripts can be added to a text area from the Edit HTML dialog. On the Community, the article Best Practices for Writing Custom JavaScript Code in Text Areas gives an introductory overview of how you can use JavaScript in text areas in Spotfire. For example scripts, see JavaScript Example Scripts.  

Note: For security reasons, there are some restrictions for using scripts. For more information, see Usage of Scripts and Manage Trust.

To reach the New Script dialog for IronPython:

You can reach the New Script dialog from several places; the text area, the graphical table, the KPI chart, and the Script - Act on Property Change dialog. Below is described how to reach the dialog from the text area.

  1. Right-click a text area and select Edit Text Area from the pop-up menu.
    Response: The Edit Text Area dialog is opened.

  2. On the toolbar, click Insert Action Control  .

  3. Click Script in the panel to the left.

  4. Click New.

To reach the New Script dialog for JavaScript:

  1. Right-click a text area and, in the menu, select Edit HTML.

  2. In the Edit HTML dialog, click Insert JavaScript, .

  3. In the Insert JavaScript dialog, click New.

Option

Description

Script name

The name of the script as you want it to be displayed in the Available scripts list of the Action Control dialog.

Description

An optional description of what the script does.

IronPython version

[Only available for IronPython.]

Lists the supported IronPython versions.

The latest supported version of IronPython is selected by default for new scripts. You specify IronPython version per script, which means that an analysis can contain scripts with different versions. If your analysis contains scripts of an older IronPython version, you do not have to convert them into a newer IronPython version, unless you want to use script functionality that is available only in newer versions. For information regarding differences between IronPython versions, please refer to the official IronPython documentation.

Script

The field for typing the IronPython or JavaScript script.

The font settings for the script field can be changed using Tools > Options, Fonts page and selecting Expression and script editor.

See Expression and Script Editor Keyboard Shortcuts for information about available shortcuts.

Script parameters

Lists any defined parameters to be used by the script.

Add

Opens the Add Script Parameter dialog where you can define new parameters to use with the script.

Edit

Opens the Edit Script Parameter dialog where you can edit the selected parameter.

Remove

Removes the selected parameter.

Run Script

[Only available for IronPython.]

Allows you to test the script by running it in the document, without your having to close this dialog. Any objects marked by print in the script definition will be shown in the Output list below.

Undo

[Only available for IronPython.]

Undoes the Run Script operation so that any results are removed from the document.

Execute in transaction

[Only available for IronPython.]

Clear the check box to avoid executing the script in the document transaction. This may be necessary if the IronPython script contains operations that do not work inside a transaction.

Output

[Only available for IronPython.]

Lists all objects marked up with "print" in the script definition.

For example, if you have a script parameter called "title", you can display its debug value by typing "print title" in the Script field.

Save As

[Only applicable for the Edit Script dialog.]

Allows you to save an edited script under a different name, so that the original script can be kept alongside the edited one.

See also:

How to Use the Text Area