Creating and Running Scripts
Tabular IQ scripts are a little different from the scripts you may know from web pages. Rather than being embedded in HTML, a script is a standalone text file containing JavaScript, which can be run as a program in its own right or packaged into an extension.
Creating a new script
To create a basic script that shows a message:
- From the File menu, choose New → Script. A blank text editor opens.
- Enter the following code:
alert("test");
Saving and running within a project
To save the script to your project and run it:
- Choose File → Save As.
- In the save dialog, enter a name such as
test_scriptand click Save. - Run the script by choosing Run Script/Query from the Tools menu, or by pressing Alt+Enter.
Saving to the file system
Scripts don’t have to live inside a project. To save a script as an ordinary file:
- Choose File → Save As External.
- Save the file as you would in any other application.
Where scripts are stored
When a script is created inside a project, the script file is managed directly by the project and is not readily accessible to other applications on the file system. When a script is saved externally, it is an ordinary file on disk, easily accessible to text editors, source control, and other tools.
Choosing between the two
Project scripts work well when a script is closely tied to the tables and queries of a particular project — for example, a script used regularly as part of a working system, where it shouldn’t be accidentally moved or separated from the data it operates on.
External scripts are the better choice when you want to edit with your own text editor, keep scripts in source control, or share them with other people. See Managing Scripts for how to work with external script folders from inside the project panel.
Next steps
- Managing Scripts — organizing project and external scripts
- Language Overview — the scripting language at a glance
- Creating a Simple Form — your first script with a user interface