[Last updated: 12th of April 2019, SAP Analytics Cloud Version 2019.7]
In the previous blog in this series, we learned how to invoke the explorer functionality on-demand in analytic applications in SAP Analytics Cloud. In this blog, let us look at how to launch Smart Discovery from analytic applications.
* * *
Smart Discovery is a powerful feature that can generate a new story using the inbuilt machine learning algorithm after analyzing your data. In stories, we have Smart Discovery embedded within the data view. But in analytic applications, we would need to launch Smart Discovery using scripting which can run for either dimensions or measures.
You can see the Smart Discovery in action below.

Smart Discovery
In analytic applications, the function SmartDiscovery.buildStory() is used to launch Smart Discovery. The parameters for this function are the Smart Discovery Settings. There are two types of Smart Discovery Settings – SmartDiscoveryDimensionSettings and SmartDiscoveryMeasureSettings. Let us see both settings in detail.
- Smart Discovery for Dimension
Consider an example of a chart showing Sales across Category. When the end user selects a category, we would need to launch Smart Discovery that can compare the selected category to other categories with respect to all measures and dimensions.

Add the following script in the onSelect() event of the chart to launch Smart Discovery:
var datasource = Chart_1.getDataSource() ;
var all_selections = Chart_1.getSelections();
var selected_member_string = ArrayUtils.create(Type.string) ;
/* By default Chart returns selected value as string */
for(var i=0; i<all_selections.length; i++ ){
var selection = all_selections[i] ;
for (var dimension in selection) {
if(dimension === “Region”){
selected_member_string.push(selection[dimension]) ;
console.log(selection[dimension]) ;
}
}
}
/*Smart Discovery accepts only MemberInfo as a parameter. So we have to get member info of the selected string using below code*/
var selected_memberinfo = ArrayUtils.create(Type.MemberInfo) ;
var all_members = datasource.getMembers(“Region”) ;
for(i=0; i< all_members.length; i++){
for(var j=0; j< selected_member_string.length; j++){
if(all_members[i].displayId === selected_member_string[j]){
selected_memberinfo.push(all_members[i]) ;
}
}
}
/* Call Smart Discovery function */
if(selected_memberinfo.length){
SmartDiscovery.buildStory(
SmartDiscoveryDimensionSettings.create(
datasource,
“Region”,
selected_memberinfo
}
);
}
Note: For Smart Discovery using Dimension, we can simplify the above script using Member class. Owing to the deprecation of the function (getSelection(), integertoString()) and class (Member) in SAC version 2019.7, we have compared a list of all dimension members with the selection from the chart to pass the selected member to smart discovery.

- Assign the selected value of Region to a local variable all_selections.
- Pass SmartDiscoveryDimensionSettings.create() as a parameter to the function buildStory() to launch Smart Discovery.
- There are three mandatory parameters for the function create()– Data Source, Dimension and Target Group.
- Target Group is an array of members that need to be focused on.
- In our example, the selected member info is passed as Target Group.
Save and Run the application. Select a category and you will get a popup to launch Smart Discovery.

Select ‘Launch Smart Discovery for Category’ to launch Smart Discovery in a new tab.
In the new tab, you can change the classification groups in the Smart Discovery panel.

Select Run to generate a Story. The story has two tabs – Overview and Key Influencers. Here you can see several visualizations that focus on the selected category, comparing it with the others.

2. Smart Discovery for a Measure
Smart Discovery for Measure will provide various insights and visualizations focusing on the given measure. Here we have a dropdown that has the list of measures. The user can select a measure and launch Smart Discovery for that measure.

Add the following script to the onSelect() of the button ‘Launch Smart Discovery’.
SmartDiscovery.buildStory(
SmartDiscoveryMeasureSettings.create(
Chart_1.getDataSource(),
Dropdown_1.getSelectedKey()
)
);

The function SmartDiscoveryMeasureSettings.create() has two mandatory parameters – Data Source and Measure. Please note that the measure list in the dropdown should have the key names of the measures.
Save & Run the application. Select the Launch Smart Discovery button. Similar to the Smart Discovery on Dimensions, a prompt will allow us to select ‘Launch Smart Discovery for Sales’ which in turn opens a new tab. Here we cannot set classification groups though you can control the dimensions and measures of the data source in Advanced Options.

Select run to generate a Story. The story has four tabs – Overview, Key Influencers, Unexpected Values and Simulation.

Please note that we can skip the Smart Discovery popup and directly launch Smart Discovery using the function SmartDiscovery.generateUrlToBuildStory(), which returns a hyperlink.
***
In the subsequent blog, we will learn about Date and Time Range functions and how to use them.
Reach out to us here today if you are interested in evaluating if SAP Analytics Cloud is right for you.