Using Script Variables

Script variables are reusable elements that store a value of a certain type.

You use script variables in scripts. They are useful, for example, for storing intermediate results that are used repeatedly in a script.

Script variables exist during the full execution time of the analytical application. The script variables you create in an application are only available for that specific application. You can define their values not only in the application, but also in the application URL by adding a specific URL parameter.

For each script variable, you can define a name, an optional description, the type, and a default value (which is optional and depends on the variable type). A script variable can be defined as an array, which means it represents a set of values of the specified type. You can use the following primitive types by opening the Type list:
  • string

    represents a text as a sequence of characters

  • boolean

    represents a logical value, either true or false

  • integer

    represents a non-fractional numerical value

    Scientific notation is not supported when you enter an integer. But when running an analytic application, the number will be displayed in scientific notation format if it is longer than 21 digits.

  • number

    represents a floating-point numerical value

    Can be entered in ordinary format or scientific notation format such as "1e+20" or "1e20". If the number is longer than 21 digits, it will be automatically displayed in scientific notation format.

In addition to the primitive types described above, you can select a wider variety of non-primitive types for the script variable from the Type list, such as Button, Category, Chart, Clock, DataSource, Table, and so on.

Creating a Script Variable
  1. In the Scripting area of the Layout, click right next to Script Variables to create a new script variable.

    Its icon and name are displayed beneath Script Variables and a new dialog, Script Variable, is opened.

  2. In the dialog, you can change the name of the script variable.

  3. (Optional)

    Type in a description for the script variable.

  4. Select the type of the script variable and whether it should be set as an array.

  5. Specify the default value depending on the type.

  6. Choose Done to close the script variable.

  7. You can now use the script variable in the scripts within this application.

Defining a Script Variable's Value via a URL Parameter
  1. Choose the script variable you want to define, and go to the Scipt Variable dialog.

  2. In the dialog, select the option Expose Variable via URL Parameter.

    Note

    For array type variables and non-primitive type variables (types other than string, boolean, integer and number), this function is not applicable and the option is disabled by default.

  3. Save the change to the analytic application and choose Run Analytic Application.

  4. In the URL of the analytic application, enter a new parameter that starts with "p_" and is followed by the script variable's name.

    For example, if you want to set the value of ScriptVariable_1 to 3.14, add the following information to the original URL:

    ;p_ScriptVariable_1=3.14
  5. Reopen your application URL.

    You will see the URL parameter value has been passed to corresponding script variables. In this way, you can initialize the application based on your needs by simply making some changes to the URL parameters.

Using a Script Variable

You can use a script variable like a local variable in your script. For example, you change the value by assigning a new value and use this value by passing it as argument when calling a function.

If you write scripts in the application, you can insert the script variable you have created by selecting it from the content assistance in the script editor. You can activate the content assistance at any place in the script by pressing CTRL + Space on your keyboard.

If you add a calculation to a dimension or measure, in the Calculation Editor you can insert the script variable you have created by typing @ in the formula. All available script variables will be automatically displayed in the drop-down list. Note that only global variables of type string, integer, and number can be referenced in the Calculation Editor. The array type is not supported.

Note
When you use the script variable as the judging expression in a IF instruction, and the expression returns a null value, the IF instruction will also return a null result. For example, if you write a script like this:

if (ScriptVariable_1 = "xxx"; 100 ; -100)

And you set the script variable to undefined when running the analytic application, the data returned and displayed in the chart is not -100, but null.

You can also define script variables as the source of dynamic text in a text widget. For detailed information about this, refer to Text.

Changing or Deleting a Script Variable

To change an existing scripting variable, click it in the Outline view. The dialog where you can make your changes is displayed again.

To delete an existing scripting variable, choose More Actions beside the script variable in the Outline view, and select Delete.

After deleting a script variable, you can add it again to the analytic application with the same variable name. If the type of the script variable is number or integer and was previously used in a calculated measure, the calculated data won't resume automatically. You need to go back to the calculated measures in the Builder panel and from the More Actions menu, select Edit Calculation. Then click OK again. After that, corresponding calculated data will resume in the analytic application.