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.
-
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.
-
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.
-
In the dialog, you can change the name of the script variable.
- (Optional)
Type in a description for the script variable.
-
Select the type of the script variable and whether it should be set as an array.
-
Specify the default value depending on the type.
-
Choose Done to close the script variable.
-
You can now use the script variable in the scripts within this application.
-
Choose the script variable you want to define, and go to the Scipt Variable dialog.
-
In the dialog, select the option Expose Variable via URL Parameter.
NoteFor 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.
-
Save the change to the analytic application and choose Run Analytic Application.
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-
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.
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.
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.
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.