How to Use the getDataSource() API in SAP Analytics Designer
The getDataSource() function returns the corresponding data source from a Table, Chart, Geo Map Layer, or from a data frame with data binding. If the data binding has no data source, it returns undefined.
Overview of getDataSource() Methods:
There are 36 functions available with the getDataSource() API. Below is a brief overview of each function and some common use cases:
Node Manipulation Methods
1. collapseNode()– Collapses the specified dimension and hierarchy node. The selection collapses the specified dimension and hierarchy nodes. Dimension name and selection (property-value pairs) are the two mandatory parameters.
2. expandNode()- The specified dimension and hierarchy node expanded. This function expands a hierarchy node. Although you can select only one node, it expands all nodes along the hierarchy path. The dimension name and a property-value pairs selection are mandatory parameters.
Dimension and Filter Management
3. copyDimensionFilterFrom()– Used to apply existing filters on several widgets. Source data dimensions filters copied from the source data source to the dimensions of the current data source. Data source is a mandatory parameter and dimension name is optional.
4. getDimensionFilters()– Returns an array of all filter values as FilterValue from the dimension filters of a dimension. (Advanced filtering is currently not supported). Mandatory parameter is dimension name.
5. getDimensionProperties()– Returns all available dimension properties of the specified dimension of a data source. Only supported on data sources from table widgets. Mandatory parameter is dimension name.
Example:

6. getDimensions()– All dimensions of the data source returned. Has no mandatory or optional parameters.
Example:

7. removeDimensionFilter()– Removes any filter that is set on the dimension without affecting Advanced Filters. Dimension name is a mandatory parameter.
Example:

8. setDimensionFilter()– Sets and overwrites any filter on the dimension except advanced filters. When you use this method with only a member ID, it performs a roundtrip to the backend to fetch the member’s description. If you pass a MemberInfo object rather than a member ID string, the method skips the backend roundtrip. Dimension name and member name (whether MemberInfo, MemberInfo[], MeasuresInfo, MeasuresInfo[], TimeRange, TimeRange[], FilterValue, or rangeFilterValue[]) are mandatory parameters.
Example:

Data Access and Exploration
9. getData()– Used to display key figure values. This improves performance by avoiding multiple requests to the backend. Returns the specific data cell value of a selection. A selection is consistent of property-value pairs specifying one row, column, or data cell. Selection parameter is mandatory.
Example:

10. getDataExplorer()– Returns the data explorer for a chart or table. If applied to any other widget’s data source, it returns undefined. This method does not require any mandatory parameters.
11. getDataSelections()– Returns the key-value pair of each cell. Specifying the offset and the limit is optional. Has three optional parameters, selections as <string> or <string[]>, offset (integer), and limit(integer).
12. getInfo()– Returns information about the specified data source through a DataSourceInfo object. Has no mandatory or optional parameters.
13. getResultSet()– Exposes the data source of both chart and table widgets. Users can specify input parameters to filter the results; if no parameters are provided, all data cells are returned. No backend trip, functions fast.
Example:

14. getMeasures()– returns all measures of the data source.. Has no mandatory or optional parameters.
Example:

Hierarchy Management
15. getHierarchies()– All hierarchies of the dimension returned. Dimension name is a mandatory parameter.
Example:

16. getHierarchy()– Used to retrieve hierarchy variables. Hierarchy set on the dimension returned. Dimension name is a mandatory parameter.
17. getHierarchyLevel()– Used to customize the display Level of the Hierarchy of the dimension returned. Specify the dimension and hierarchy level that you would like to set or retrieve. This method supports only tables and charts. Dimension name is the mandatory parameter.
18. setHierarchy()– The hierarchy on the dimension is set. Dimension and hierarchy name are mandatory parameters.
Example:

19. setHierarchyLevel()– The hierarchy level of the dimension is set. Operation ignored if the dimension or its hierarchy level is invalid. Dimension name is a mandatory parameter, level is an optional parameter.
Example:

Member Management:
20. getMember()– Returns the MemberInfo object for a given member ID. Dimension name and member ID are mandatory parameters, and hierarchy info is optional.
You can use this method as part of the Planning API and the getDataSource() API. When calling getMember() through getDataSource(), consider the current active hierarchy. If the active hierarchy is set to Flat Presentation, passing the memberId is sufficient as a parameter.
Example:
Table_1.getDataSource().getMember(“ENTITY”, “E1000”);
Returns the member info object
{id: ‘E1000’, description: ‘InsightCubes UAE’, dimensionId: ‘Entity’, …}
If the widget sets the current active hierarchy of the “Entity” dimension, pass the full memberId as a parameter to the API function.
Table_1.getDataSource().getMember(“ENTITY”, “[ENTITY].[parentId].&[E1000]”);
21. getMemberDisplayMode()– Returns the display mode for members of the dimension. Dimension name is the only mandatory parameter.
22. getMembers()– Members of the dimension are returned. Conducts a backend roundtrip. Use the available options parameter to limit the list of returned members. Dimension name is a mandatory parameter, and options (members options as a JSON object to method arguments) is optional.
Example:

23. getResultMember()- The result member is returned. Dimension name and selection are mandatory parameters. getResultMember() Is used to get member specific information of the specified member. This function provides the ResultMemberInfo object which contains id, description, and parentId.
For a dimension which has attributes, the attributes will be provided as additional properties of the ResultMemberInfo object. This function does not conduct a backend trip, thus functions faster. Only the visible properties in the widget will be included in the resultMemberInfo object.
24. setMemberDisplayMode()– Display mode for members of the dimension is set. Operation not supported for Geo maps. Dimension name and member display mode are two mandatory parameters.
Refresh and Runtime Control
25. refreshData()– Simultaneously updates and refreshes data of the widgets associated with the data source. If you’ve added, updated, or deleted members, use DataSource.refreshData() if you need the chart or table to reflect the modified members. The Refresh Data API works with the Timer API to refresh a widget at regular intervals. Has no mandatory or optional parameters.
26. isRefreshPaused()– This method is deprecated, use getRefreshPaused() instead.
27. getRefreshPaused()– Used to enable or disable data refresh at runtime. Has no mandatory or optional parameters. Used with the following values of pause mode: PauseMode.On always pause refresh, PauseMode.Off aways refresh, PauseMode.Auto refreshes Active Widgets Only.
28. setRefreshPaused()– Enable or disable data refresh at runtime. This method can be used with a Boolean PauseMode or with the following values:
PauseMode.On– always pausePauseMode.Off– always refreshPauseMode.Auto– refresh active widgets only
Only charts and tables support this operation.
PauseMode (Auto, Off, On) is a mandatory parameter.
Example:

Variables and Planning
29. copyVariableValueFrom()– Used to copy the variable value from one, several, or all variables of a data source to another variable. Copies the variable value if specified and all variable values of the data source if no variable value is specified. Data source is a mandatory parameter and variable name is optional.
30. getVariableValues()– Get the values of a variable. Returns an array of all variable values as VariableValue objects. Each value in the array is an instance of either single, multiple or range value, which all inherit from VariableValue. To access its type-specific properties, cast the instance to the corresponding type first, using the type property. For accessing its type-specific properties, cast the instance to the corresponding type first, using the type property. Variable name is a mandatory parameter.
Example:

31. getVariables()– All variables of the data source are returned as an array of all variables as VariableInfo objects. Has no mandatory or optional parameters.
In the example below, all variables names of a data source are printed to the browser console:

32. removeVariableValue()– Removes the value of a variable from a data source. Variable name is a Mandatory parameter.
33. setVariableValue()- Value of the variable for the data source on the application is set by default. Other rules apply depending on use case. Variable name and variable value (VariableValue, VariableValue[]) are mandatory parameters, options (SetVariableValueOptions: “A set of values to describe the variables to retrieve”) is optional.
If the variable supports single variable values, you can set a variable value as follows:
Example:
Table_1.getDataSource().setVariableValue(“VAR_NAME”, {value: “5”}); or, alternatively,
Table_1.getDataSource().setVariableValue(“VAR_NAME”, “5”);
If the variable supports excluding a single variable value, you can set the variable value as follows:
Example:
Table_1.getDataSource().setVariableValue(“VAR_NAME”, {exclude: true, value: “5”});
Deprecated / Legacy Methods
34. isResultEmpty()– Returns true if the data source query result is empty, meaning no data cells were returned. Has no mandatory or optional parameters.
35. openPromptDialog()– The Prompt dialog for the model used by this data source is opened. Has no mandatory or optional parameters.
36. getComments() is deprecated. Use Table.getComments() instead. Returns data source comments. You can retrieve comments only from tables. No mandatory or optional parameters apply.