Objective
After completing this lesson, you will be able to create a data action technical object in a story and extend a button widget to run it.
Data Actions and Button Widgets
Why would you extend a button with scripting?
Button widgets can be extended to:
- Display custom dialogs and popup messages. For example, buttons can be extended to provide the user with personalized messages and dialogs while data action starters only display the built-in system dialogs.
- Select the context of another widget (such as a data table) and automatically apply it to your data action technical object. Buttons can be extended to eliminate the need for you to manually provide values in a prompt dialog.
- Add buttons in view mode to allow users to quickly apply settings only available in edit mode. For example, if a planner doesn’t have edit access to a story, they can press a button to change a property such as setting a table to read-only.
- Display a list of versions for a data table.
- Allow easy access to commonly-used toolbar options such as refresh and revert, making it easier for planners because they no longer need to search for options in the toolbar.
Data Actions
A data action is a flexible planning tool for making structured changes to a version of model data, such as copying data from one model to another. However, there are two ways for you to use data actions in a story:
- Using a Data Action Starter widget.
This topic is covered in detail in the Leveraging Advanced Features in SAP Analytics Cloud for Planning course.
- Using a Data Actions Technical Object and related APIs. You can do the following:
- Perform data actions.
- Set parameter values of data actions.
- Read parameter values of data actions.
Business Scenario: Create a Data Action Button
Watch this video to learn more about the team's requirement for a data action button that is extended with scripting.
⠀
Your team has created a story that is used by all planners on the team. The story currently has data actions but when they're clicked, planners receive a system message that says Please wait while the data action is running, a busy indicator, and an option to run the job in the background.
The team prefers that any changes are blocked until the data action is finished and data is refreshed automatically. They do not want the Run in Background option to be available to planners.
You suggest extending the story with a data action button. The button will only appear when a private version are available and will not allow planners to run the data action in the background.
After working with your colleague Christine to fully understand the business requirement for the extended data action button, you'll create a data action button that:
- Only appears when there's a private version.
- Copies and refreshes data.
- Has a busy indicator without a dialog box while it's running.
- Tells the planner when it runs successfully.
Story Setup
Before adding scripting, you must first create and configure the data action and then add the data action technical object to your story.
In the following example, data action technical object DataAction_1 has been added to the planning story and configured with the data action and parameters as shown.
Add a button widget to the story page. This BTN_Copy button will be used to run the data action.
View Time Visibility: Verify that the Styling panel for the button to ensure that it is set to Hidden. This will ensure that the button doesn't temporarily appear while the script that you plan to add to check if there are private versions is running
Code Used in the Scenario
Add Script to a Button to Run the Data Action and Refresh Data
For the BTN_Copy button, select More Actions and add an onClick script to it.
The following script is used to run the DataAction_1 data action technical object when the button is selected to copy and then refresh the data in the table:
12
DataAction_1.execute();
TBLPLANNING.getDataSource().refreshData();
Show/Hide Data Action Button
Create the SO_Planning – updateButtonVisibility script object and add code below to show and hide the BTN_Copy button depending on if a private version exists or not:
12345678910
// retrieve all private versions available in the model
var selectedPrivateVersion = TBLPLANNING.getPlanning().getPrivateVersions();
// if private version exists
if (selectedPrivateVersion.length > 0) {
BTN_Copy.setVisible(true);
}
else {
BTN_Copy.setVisible(false);
}
Check for Private Versions on Page Load
The button is set to be hidden by default, so add the following code to Page_1 - onInitialization:
12
//Call Global Script function to populate story with button if private version exists
SO_Planning.updateButtonVisibility();
Check for Private Versions When a Table is Changed
Once the table is updated, it's important to check if there are private versions, so add the following code to TBLPLANNING - onResultChanged:
1
SO_Planning.updateButtonVisibility();
Add Busy Indicator
Add a busy indicator that appears when the Copy and Refresh Data button is clicked to show the user that the data action is running:
1
Application.showBusyIndicator();
Hide the busy indicator when the data action is finished running:
1
Application.hideBusyIndicator();
Add Custom Message
Add the following code to display the custom message once the data action runs successfully:
1
Application.showMessage(ApplicationMessageType.Success,"The data action has run successfully and the table has refreshed.");
Create a Data Action Button with Scripting
Task 1: Create a Data Action Button with Scripting to Copy and Refresh Data
Task Flow: In this practice exercise, you will:
- Add a data action technical object to the story and configure the parameters.
- Add scripting to the button to run the data action to copy and refresh data.
- Add scripting to a button widget so that it only appears if there is a private version.
Task 2: Add Scripting to a Data Action Button to Display a Busy Indicator and a Custom Message
Task Flow: In this practice exercise, you will:
- Add scripting to the button to show/hide a busy indicator.
- Add scripting to the button to add a success message.