Use getVariablevalues API
You can use API getVariableValues() in analytic applications and optimized stories, which returns an array of the current values of the specified variable.
About getVariableValues() API
getVariableValues( variable: string | VariableInfo ) : VariableValue[]
The following example shows how the API is used:
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 access type-specific properties, define the VariableValueType property in scripting. See the following section.
Note
Currently for variables using SAP BW models, getVariableValues() and other variable-related APIs can only access input-ready ones. Customer Exit variables can’t be accessed via these APIs.
Access 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
What you set with setVariableValue is not necessarily the same as what is returned from getVariableValues.
For example, you have several options to set multiple values, and the following two are equivalent:
Sample Code
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 } ]);
The getVariableValues API will always return as few VariableValue objects as possible, grouping all single
values with the same sign (including or excluding) into one. In the previous example, an array with only one object is returned by
getVariableValues:
[ { values: [ "DE", "FR" ], exclude: true } ]