Using the setVariableValue API in a Story Script

Objective

After completing this lesson, you will be able to use the setVariableValue API to set multiple variables in a story script.

setVariableValue API

This lesson is relevant for story developers who work with queries from an SAP Business Warehouse (SAP BW) system as data source for their stories.

Points to Consider

There are two things to consider when deciding if you want to use variables from a BEx Query out of an SAP BW system in your scripts, as these variables are quite expensive objects from a performance perspective.

  1. All values that you set as variable values need to be validated before they are used.

    The validation means that there is a requirement for an extra backend request.

    In the Performance Insights dialog, these validation requests will be shown as additional Query model metadata requests.

    SAP Performance Insights dialog showing additional validation requests shown as additional Query model metadata requests.
  2. Changing a single variable can lead to a re-rendering of multiple widgets.

    Depending on the variable handling setting (story-wide or widget-specific), the story design itself, and if the variable is used in multiple widgets, then changing a single variable can lead to multiple widgets being rendered again.

Recommendations

Once you have considered how using variables can impact on your story performance, there are two recommendations for using variables effectively. These are only general recommendations, and not meant to be followed as strict rules, as differences may occur depending on the specific story design.

  1. Using multiple variable values.

    If you want to set multiple variable values in a script, keep the setVariableValue() APIs together, ideally one line after the other. They are, where possible, automatically merged into one request. This reduces the number of backend round trips and increases the performance. For example:

    Code Snippet
    12
    Table_1.getDataSource().setVariableValue("U00_VAR_MON_001","201507"); Table_1.getDataSource().setVariableValue("U00_VAR_MON_002","201508");
    Performance Insights dialog showing the performance of the onClick event script when BTN_2var is selected. The code used is written above the image.

    If you, for any reason, can't write them together, be aware that some APIs (for example, those that reference the data source, sorts the values, etc.), prevent the system from merging the requests. For example:

    Code Snippet
    123
    Table_1.getDataSource().setVariableValue("U00_VAR_MON_001","201507"); Table_1.sortByMember("0D_NW_PRID__0D_NW_PRCAT",SortOrder.Descending); Table_1.getDataSource().setVariableValue("U00_VAR_MON_002","201508");
    Performance Insights dialog showing the performance of the onClick event script when BTN_VarSortVar is selected. The code used is written above the image.
  2. Using a filter instead of a variable.

    In the case that the variable within the query is only used to let the user select a filter for a dimension, then consider using a filter instead.

    Setting a filter value with the setDimensionFilter() API, in general, does not require the extra validation round trip.

Log in to track your progress & complete quizzes