In this blog post, I will provide you with a comprehensive and step-by-step explanation of how to retrieve property values from any dimension within SAP Analytics Cloud (SAC). I will walk you through the intricacies of the process, ensuring a thorough understanding of the methods and techniques involved.
There was already an easier way to retrieve properties using the Planning Model's getMembers() method. However, in the future they may restrict access to master data for non-generic dimensions.
If you are using getMembers with non-generic dimension you we see error like this in console:-
"Dimension type VersionDim is not supported"
As a result, we had to find an alternative method to obtain properties from dimensions, which led us to using tables in stories or analytical applications. Let's get started.
Prerequisites
- An active SAP Analytics Cloud account
- Access to a story or analytical application where you can create tables and buttons
Steps to Retrieve Property Values
- Create a table in your story or analytical app:
- Open your story or create a new one in SAP Analytics Cloud.
- Add a table to the canvas.
- In the table, include all dimensions for which you need property values. For this example, let's consider the 'Version' dimension.
Make sure that your tables have some data in table, so table will show properties as well. Even if your table is unbooked and have no data. it won't work. So you should have some data.
2. Show the property of the dimension:
- Right-click on the 'Version' dimension in the table.
- From the context menu, select 'Show/Hide' and then choose your desired property from the 'Properties' option.
3. Create a button and add the following JavaScript code:
Insert the following code in the onClick function:
/*
var selection = {
"DIMENSION_NAME": "PROPERTY_ID"
};
*/
var selection = {
"Version": "public.Actual"
};
var resultSet = Table_1.getDataSource().getResultSet(selection, 0, 1);
// Log the entire result set to the console
console.log(resultSet);
// Access the specific property value (e.g., START_DATE) from the result set
/* var startDate = resultSet[0]["DIMENSION_NAME"].properties["DIMENSION_NAME.PROPERTY_ID"]; */
var startDate = resultSet[0]["Version"].properties["Version.START_DATE"];
// Log the property value to the console
console.log(startDate);
// Output: 202312
Console Output
Explanation of the Code
The provided JavaScript code demonstrates how to obtain property values from the 'Version' dimension in SAC. First, we create a selection object specifying the desired dimension value. We then use the getResultSet() method to retrieve the data, limiting the result to one entry. Finally, we access the specific property value, in this case, 'START_DATE', from the result set and log it to the console.
Conclusion
By following these steps and utilizing the provided code, you can efficiently retrieve property values from any dimension in SAP Analytics Cloud. This method provides a reliable solution even after the 2024 Q4 update restrictions.