Using getVariablesValues API

The new API getVariableValues() returns an array of the current values of the specified variable:

API Definition
getVariableValues( variable: string | VariableInfo ) : VariableValue[]
The following example shows how the API is used (sample call).
Sample Code
var values = Table_1.getDataSource().getVariableValues("V_Country"); // 'values' is an array of VariableValue objects

Each value in the array is an instance of either SingleVariableValue, MultipleVariableValue or RangeVariableValue, which all inherit from VariableValue. To work with such an instance (which means access its type-specific properties), it needs to be cast to the corresponding type first, using the type property. Please see the following section

Accessing Type-Specific Properties
Sample Code
var value = Table_1.getDataSource().getVariableValues("V_Country")[0];
switch (value.type) {
    case VariableValueType.Single:
        var singleValue = cast(Type.SingleVariableValue, value);
        console.log(singleValue.value); // can access the 'value' property now
        break;
    case VariableValueType.Multiple:
        var multiValue = cast(Type.MultipleVariableValue, value);
        console.log(multiValue.values); // can access the 'values' property now
        break;
    case VariableValueType.Range:
        var rangeValue = cast(Type.RangeVariableValue, value);
        console.log(rangeValue.from); // can access the 'from' property now
        console.log(rangeValue.to);   // can access the 'to' property now
        // further range properties: 'less', 'lessOrEqual', 'greater', 'greaterOrEqual'
        break;
    default:
        break;
}
Note
Note that what you set with setVariableValue is not necessarily the same that is returned from getVariableValues. For example you have several options to set multiple values. The following two lines are equivalent:
Sample Code
Setting multiple values
Table_1.getDataSource().setVariableValue("V_Country", { values: [ "DE", "FR" ], exclude: true });

Table_1.getDataSource().setVariableValue("V_Country", [ { value: "DE", exclude: true }, { value: "FR", exclude: true } ]);
getVariableValues will always return as few VariableValue objects as possible, grouping all single values with the same sign (that is including or excluding) into one values object. In the previous example, an array with only one object is returned:
Sample Code
returned by getVariableValues
[ { values: [ "DE", "FR" ], exclude: true } ]
In SAP BW models you can define variables that correspond to user-modifiable settings like filters or hierarchies. For example, setting a variable value sets the exact same value as the filter on the related dimension.
Note

Synchronization in the other direction is not performed by getVariableValues. Thus, the API will still return the same variable value, even though the user might have modified the filter in the meantime. To retrieve the current value of such special variables, use getDimensionFilters() instead (or likewise, getHierarchy() for hierarchy variables).