Before looking at the global variable, let us check the box by reviewing local variables, which are straightforward.
Local variables are declared within a scripting event and can be assigned a value during declaration. It can be of type String, Integer, Number or Boolean and it can also be an array of elements of the same type.
In the following example, a local variable ‘reg’ is created and the selected key from the dropdown is assigned. Then the local variable is used to filter Region of the Chart.
Unlike local variables, global variables need to be declared in a separate panel. As the name suggests, global variables can be used across different scripting events and across widgets. Following are the steps involved.
Declaring a Global Variable
- Select the plus (+) icon in the Global Variables view.
- Once added a new panel opens where you can configure it.
- Here you can change the name, add a description, change the type, make the variable an array, assign a default value and expose the variable to be used via URL parameter.
- The Global Variable can be of type String, Integer, Number or Boolean.
- For using a global variable as URL parameter, the name should start with the prefix “p_”.
- Default values cannot be assigned for a global variable that is declared an array.
Using a Global Variable
Consider an example where there is a filter panel with three dropdowns and a button. The user can change the dropdown values and then select the ‘Apply Filters’ button to filter the table.
- First declare three Global Variables of type string to be used in scripting.
- Now on the onSelect() event of each dropdown assign the selected key value to the respective global variable.
- On the onSelect() of the button ‘Apply Filters’ use the Global Variables to set a dimension filter
- Save & run the application. Change the values in dropdown and select the apply filter button to filter the table.
* * *
In the subsequent blog, we will look at scripting APIs in analytic application.
Reach out to our team here if you are interested to evaluate if SAP Analytics Cloud is right for you.