2024 Dec 15 9:17 PM - edited 2024 Dec 25 7:39 AM
The Best Run Bike model was used as the model in the study.
Hello! Have you ever faced a situation where precise variable selection is mandatory to ensure accurate data display in your reports? If you answer yes, in this blog I’ll walk you through an interactive popup-based variable selection screen in SAP Analytics Cloud (SAC). The example covers a scenario where users must select Country and Customer Status before continuing, ensuring better data relevance and user experience.
Let’s explore this hands-on implementation step by step, breaking down the scripting logic behind creating this functionality.
Variable screens in SAC are essential for guiding users to make the right data selections before interacting with dashboards. By using a popup for variable selection:
This method is especially useful in scenarios where filtering data by key dimensions (like Country or Customer Status) is critical for business decisions.
Here’s what we’ll achieve:
//open Popup_Screen
Popup_Screen.open();
//call function which fills dropdowns
VariableObjects.fillVariableDropdowns();
//call function which pause widgets refresh on the initial state
VariableObjects.pauseOn();
The values in the dropdown lists are taken from the current data set and added to the corresponding list. For this, the fillVariableDropdowns() function is defined.
This function takes the Country, Customer Status, and Sales Agent fields from the data source and adds them to the dropdowns accordingly. This way, when users open the popup, they can see all the options for that field.
Dropdown Information:
fillVariableDropdowns() function:
//Create variables selected for Country, selected2 for Sales Agent and selected3 for Customer Status variables
var selected = Table_13.getDataSource().getMembers("Country");
var selected2= Table_13.getDataSource().getMembers("Sales_Agent");
var selected3= Table_13.getDataSource().getMembers("Customer_Status");
//Related members are added to the dropdown of each variable
if(selected.length>0) {
for( var i=0; i<selected.length; i++) {
Dropdown_Country.addItem(selected[i].id, selected[i].description);
}
}
if(selected2.length>0) {
for( var k=0; k<selected2.length; k++) {
Dropdown_SalesAgent.addItem(selected2[k].id,selected2[k].description);
}
}
if(selected3.length>0) {
for( var j=0; j<selected3.length; j++) {
Dropdown_CustStatus.addItem(selected3[j].id,selected3[j].description);
}
}
To improve performance and avoid unnecessary backend queries, data refresh is paused while the popup is active.
pauseOn: Pauses the refresh for all widgets (tables, charts, etc.).
Table_12.getDataSource().setRefreshPaused(PauseMode.On);
Chart_10.getDataSource().setRefreshPaused(PauseMode.On);
Table_13.getDataSource().setRefreshPaused(PauseMode.On);
pauseOff: Resumes the refresh once the user completes their selections.
Table_12.getDataSource().setRefreshPaused(PauseMode.Off);
Chart_10.getDataSource().setRefreshPaused(PauseMode.Off);
Table_13.getDataSource().setRefreshPaused(PauseMode.Off);
3. Handling User Actions
The popup includes three buttons:
When the Set button is clicked:
Cancel Button Logic
Close the popup screen.
Popup_Screen - onButtonClick
//Country and Customer status selections are mandatory, Sales Agent is not.
//If the selection is empty, it stops the page refresh.
//The code block that runs when the Set button was clicked
if(buttonId === "buttonSet") {
//get selections of dropdowns
var selectedCountry=Dropdown_Country.getSelectedKey();
var selectedAgent= Dropdown_SalesAgent.getSelectedKey();
var selectedStatu= Dropdown_CustStatus.getSelectedKey();
//If Country and Customer Status are not selected
if(selectedCountry===undefined && selectedStatu===undefined) {
Popup_Screen.open();
Application.showMessage(ApplicationMessageType.Error,"Country selection is mandatory.");
Application.showMessage(ApplicationMessageType.Error,"Customer Status selection is mandatory.");
VariableObjects.pauseOn(); //Stops the refresh.
}
//Only if the Country is not selected
else if(selectedCountry===undefined) {
Popup_Screen.open();
Application.showMessage(ApplicationMessageType.Error,"Country selection is mandatory.");
VariableObjects.pauseOn(); //Stops the refresh.
}
//Only if the Customer Status not selected.
else if(selectedStatu===undefined) {
Popup_Screen.open();
Application.showMessage(ApplicationMessageType.Error,"Customer Status selection is mandatory.");
VariableObjects.pauseOn(); //Stops the refresh.
}
//If Country and Customer Status are both selected and Sales Agent selection is up to the user and selected
else {
Table_12.getDataSource().setDimensionFilter("Country", selectedCountry);
Chart_10.getDataSource().setDimensionFilter("Country", selectedCountry);
Table_13.getDataSource().setDimensionFilter("Country", selectedCountry);
Table_12.getDataSource().setDimensionFilter("Customer_Status", selectedStatu);
Chart_10.getDataSource().setDimensionFilter("Customer_Status", selectedStatu);
Table_13.getDataSource().setDimensionFilter("Customer_Status", selectedStatu);
Table_12.getDataSource().setDimensionFilter("Sales_Agent",selectedAgent);
Chart_10.getDataSource().setDimensionFilter("Sales_Agent",selectedAgent);
Table_13.getDataSource().setDimensionFilter("Sales_Agent",selectedAgent);
VariableObjects.pauseOff();
Popup_Screen.close();
}
}
//Runs when the Cancel button was clicked
if(buttonId === "buttonCancel") {
Popup_Screen.close();
}
Reset Selections Button Logic
Resets the selections in dropdowns.
Dropdown_Country.setSelectedKey("undefined");
Dropdown_SalesAgent.setSelectedKey("undefined");
Dropdown_CustStatus.setSelectedKey("undefined");
Variable Screen Button Logic
With the Variable Screen button on the page, the popup with the Variable screen is made visible.
//onClick
Popup_Screen.open();
When implemented, this logic ensures that:
Implementing a variable screen with popups in SAC not only improves data relevance but also boosts overall performance and user satisfaction. This approach is ideal for scenarios where precise filtering is essential before any data is displayed.
I hope this guide helps you design similar solutions for your SAC projects. Stay tuned for more tips, and happy scripting!
Feel free to share your thoughts and questions in the comments below!
SAP Community SAP Analytics Cloud Cloud SAP Analytics Cloud, analytics designer
Request clarification before answering.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.