In the previous blog in this series, we learnt about various script functions. In this blog, let us look at how to leverage global variables in scripting.

Local Variables

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.

SAP Analytics Cloud – Application Design Series: 7 – Global Variables

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.

SAP Analytics Cloud – Application Design Series: 7 – Global Variables

Global Variables

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

  1. Select the plus (+) icon in the Global Variables view.
    SAP Analytics Cloud – Application Design Series: 7 – Global Variables
  2. Once added a new panel opens where you can configure it.
    SAP Analytics Cloud – Application Design Series: 7 – Global Variables
  3. 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.
  4. The Global Variable can be of type String, Integer, Number or Boolean.
  5. For using a global variable as URL parameter, the name should start with the prefix “p_”.
  6. 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.

SAP Analytics Cloud – Application Design Series: 7 – Global Variables

  1. First declare three Global Variables of type string to be used in scripting.
    SAP Analytics Cloud – Application Design Series: 7 – Global Variables
  2. Now on the onSelect() event of each dropdown assign the selected key value to the respective global variable.
    SAP Analytics Cloud – Application Design Series: 7 – Global Variables
    SAP Analytics Cloud – Application Design Series: 7 – Global Variables
    SAP Analytics Cloud – Application Design Series: 7 – Global Variables
  3. On the onSelect() of the button ‘Apply Filters’ use the Global Variables to set a dimension filter
    SAP Analytics Cloud – Application Design Series: 7 – Global Variables
  4. Save & run the application. Change the values in dropdown and select the apply filter button to filter the table.

SAP Analytics Cloud – Application Design Series: 7 – Global Variables

* * *

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.

Subscribe to our Newsletter

5920 Windhaven Pkwy
Plano TX 75093.

+1 888-227-2794

+1 972-232-2233

+1 888-227-7192

solutions@visualbi.com