Extending Button Widgets to Run Data Action Technical Objects

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:

  1. Using a Data Action Starter widget.Data Action Starter in an SAP Analytics Cloud story. Toolbar is open with the Data Action Starter settings open in the builder panel.

    This topic is covered in detail in the Leveraging Advanced Features in SAP Analytics Cloud for Planning course.

  2. 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.
    Data action technical object inserted from the left side panel of an SAP Analytics Cloud story with the Data Action Configuration panel open on the right side of the screen.

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.

Data action dialog

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:

  1. Only appears when there's a private version.
  2. Copies and refreshes data.
  3. Has a busy indicator without a dialog box while it's running.
  4. 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.

Data action configuration in a story.

Add a button widget to the story page. This BTN_Copy button will be used to run the data action.

SAP Analytics Cloud story with the Outline panel open on the left with the BTN_Copy button widget highlighted. The corresponding button is highlighted on the story page.

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

Button Styling panel open with the View Time Visibility highlighted and set to Hidden.

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:

Code Snippet
12
DataAction_1.execute(); TBLPLANNING.getDataSource().refreshData();
Data action configured for on click action. Lines 1 and 2.

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:

Code Snippet
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); }
Code used in Script Objects to show and hide the button. Lines 7 and 10.

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:

Code Snippet
12
//Call Global Script function to populate story with button if private version exists SO_Planning.updateButtonVisibility();
Script for onInitialization for Page 1.

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:

Code Snippet
1
SO_Planning.updateButtonVisibility();
Code used in TBLPLANNING to update button visibility after a change has been made to the table. Line 1.

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:

Code Snippet
1
Application.showBusyIndicator();

Hide the busy indicator when the data action is finished running:

Code Snippet
1
Application.hideBusyIndicator();
Code used in BTN_Copy to show and hide the busy indicator. Lines 1 and 4.

Add Custom Message

Add the following code to display the custom message once the data action runs successfully:

Code Snippet
1
Application.showMessage(ApplicationMessageType.Success,"The data action has run successfully and the table has refreshed.");
Code used in BTN_Copy to display custom message. Line 5.

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.