Skip to Content
Technical Articles

SAP Analytics Cloud – Analytic Applications JS script data structures for data source

When using JS script in SAP Analytics Cloud Analytic Applications, the component DataSource is used a lot. We can get several attributes from the data source component. This blog includes the data structure of Dimensions, dimension members, measures,  hierarchies, selections, data, dimension display mode and result member.

 

Here use model BestRunJuice_SampleModel as the example. You can get the model in content network.

Take below chart as an BAR chart example by using the BestRunJuice_SampleModel.

 

In the canvas function onInitialization, first to get data source of this chart.

 

  • Get members of this data source.

var chart1DataSource = Chart_1.getDataSource();
var chart1Dimensions = chart1DataSource.getDimensions();

The dimensions data structure is as below:

{id: "Date_703i1904sd", description: "Date"}
{id: "Location_4nm2e04531", description: "Location"}
{id: "Product_3e315003an", description: "Product"}
{id: "Sales_Manager__5w3m5d06b5", description: "Sales Manager"}
{id: "Store_3z2g5g06m4", description: "Store"}
{id: "Version_BestRunJsold_V", description: "Category"}
{id: "Account_BestRunJ_sold.accType", description: "Account Type"}
{id: "Store_3z2g5g06m4.Store_DisplayName", description: "Store_DisplayName"}
{id: "Store_3z2g5g06m4.Store_GEOID", description: "Store_GEOID"}
{id: "@MeasureDimension", description: "Account"}
  • Get the dimension members of this data source specified the dimension “Location_4nm2e04531”.

var chart1Members = chart1DataSource.getMembers("Location_4nm2e04531");

The members data structure is below:

{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA1]", description: "California", displayId: "SA1"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT1]", description: "Los Angeles", displayId: "CT1"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT2]", description: "San Francisco", displayId: "CT2"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT3]", description: "San Diego", displayId: "CT3"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT4]", description: "Sacramento", displayId: "CT4"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT5]", description: "San Jose", displayId: "CT5"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT6]", description: "Oakland", displayId: "CT6"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT7]", description: "Santa Barbara", displayId: "CT7"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT8]", description: "Beverly Hills", displayId: "CT8"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA2]", description: "Nevada", displayId: "SA2"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT10]", description: "Reno", displayId: "CT10"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT11]", description: "Henderson", displayId: "CT11"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT12]", description: "Carson City", displayId: "CT12"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT9]", description: "Las Vegas", displayId: "CT9"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA3]", description: "Oregon", displayId: "SA3"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT13]", description: "Portland", displayId: "CT13"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT14]", description: "Salem", displayId: "CT14"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT15]", description: "Eugene", displayId: "CT15"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT16]", description: "Gresham", displayId: "CT16"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT17]", description: "Hillsboro", displayId: "CT17"}
{dimensionId: "Location_4nm2e04531", id: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[CT18]", description: "Beaverton", displayId: "CT18"}

 

  • Get measures of this data source.

var chart1Measures = chart1DataSource.getMeasures();

The measures data structure is as below:

{dimensionId: "@MeasureDimension", id: "[Account_BestRunJ_sold].[parentId].&[Gross_Margin]", description: "Gross Margin"}
{dimensionId: "@MeasureDimension", id: "[Account_BestRunJ_sold].[parentId].&[Discount]", description: "Discount"}
{dimensionId: "@MeasureDimension", id: "[Account_BestRunJ_sold].[parentId].&[Original_Sales_Price]", description: "Original Sales Price"}
{dimensionId: "@MeasureDimension", id: "[Account_BestRunJ_sold].[parentId].&[Price_fixed_]", description: "Price (fixed)"}
{dimensionId: "@MeasureDimension", id: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]", description: "Quantity sold"}

 

  • Get hierarchies of this data source specified the dimension “Product_3e315003an”

var chart1Hierarchies = chart1DataSource.getHierarchies("Product_3e315003an");

The hierarchies data structure is below:

{id: "Product_Catego_3o3x5e06y2", description: "Product Category"}
{id: "@FlatHierarchy", description: "Flat presentation"}

 

  • Get selections of this data source

var chart1Selections = chart1DataSource.getDataSelections();

The selections data structure is below:

{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA1]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC4]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA1]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC1]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA1]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC2]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA1]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC3]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA2]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC4]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA2]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC1]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA2]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC2]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA2]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC3]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA3]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC4]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA3]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC1]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA3]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC2]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}
{Location_4nm2e04531: "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA3]", Product_3e315003an: "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC3]", @MeasureDimension: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"}

 

  • Get data from this data source specified selection as below.

var selection = {
"@MeasureDimension": "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]",
"Location_4nm2e04531": "[Location_4nm2e04531].[State_47acc246_4m5x6u3k6s].&[SA1]",
"Product_3e315003an": "[Product_3e315003an].[Product_Catego_3o3x5e06y2].&[PC4]"
};
var chart1Data = chart1DataSource.getData(selection);

The data structure is below:

{formattedValue: "37.25", rawValue: "37250868"}

 

  • Get dimension display mode of this data source specified the dimension “Location_4nm2e04531”.

var chartDisplayMode = chart1DataSource.getMemberDisplayMode("Location_4nm2e04531");

The return data is below:

Description

 

  • Get result member from this data source specified dimension and selection.

var charResultMember = chart1DataSource.getResultMember("@MeasureDimension", {"@MeasureDimension": "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]"});

The result member data structure is below:

{id: "[Account_BestRunJ_sold].[parentId].&[Quantity_sold]", description: "Quantity sold", parentId: undefined}

 

The above data structures represent a clear view for the possible attributes which can get from data source component.

3 Comments
You must be Logged on to comment or reply to a post.
  • Thank you for your share. And I have a quersion. If I want to get the bar chart dimension value, how can I write js? For example, I want to get Alcohol when I click the first bar. Thank you.

    • you can get the product name by using below¬† in the Chart_1-onSelect:

      var selection = Chart_1.getSelections();
      var dataSource = Chart_1.getDataSource();
      var member = dataSource.getResultMember(“Product_3e315003an”,selection[0] );

       

  • Hi Peng,

     

    Thanks for the informative blog. I’m new to SAC and would like to understand below query:

    1. I’ve a chart_1 and let’s say I assign the data source of chart_1 to var – chart1DataSource.
    2. Further to that, I want to know Measures of that chart, so I write this –
      var chart1Measures = chart1DataSource.getMeasures();
    3. HOW to display the output of VARIABLE – chart1Measures in ANALYTIC APPLICATION -> Edit Scipt screen.

    Please share your insights. Thank you.