Using the Optimized Story Experience API Reference to Enhance a Story

Objective

After completing this lesson, you will be able to use the Optimized Story Experience API Reference in SAP Analytics Cloud to enhance a story.

Using APIs in Scripting

Access the Optimized Story Experience API Reference Guide

You can create interactive and highly custom-defined stories using APIs provided by SAP Analytics Cloud. With the Optimized Story Experience API Reference Guide, you have direct access to all available APIs that you can use in your stories.

All objects, functions, properties, methods, and events available in such scripts are listed in this API reference.

The scripts consist of one or more statements written in the JavaScript subset language used by SAP Analytics Cloud, which follow a specific syntax. You can use these scripts in the script editor to enhance your stories in advanced mode.

Explore APIs in the Optimized Story Experience API Reference Guide

You can explore the APIs in many ways. In this example, we searched for the onClick event and you can see all the components that offer scripting on the onClick event displayed below the search field.

Searching by Event. In this example, onClick.

You can also look for the available scripting grouped by widget. In this example, Table was selected to view the available scripting. These APIs can also be used for other widgets. For example, in the scenario that follows getDataSource is used for Charts.

Available APIs for the Table widget.

Scenario: Using getDataSource in Call Statements

Let’s use the example getDataSource, which is commonly used for different widgets such as charts and tables.

Highlight around getDataSource on left and the details on the right.

The API getDataSource returns the data source of the widget where this API is used, for example, CH_TaxesPerMonth.getDataSource(); returns data source of this chart.

Note

If you use a chart in a story, the data source is often a model. If you use two chart widgets that use the same model in your story (for example, one which displays data by region and the second data by product) then you still need getDataSource on both charts to enable other actions like filtering the chart.

Syntax Used in Call Statements

Call statements execute an API method of an object. The basic syntax for call statements is: <Widget>.<Method>(<Arguments>);

<Widget> is the name of a data source alias or a component in your story. Ask yourself, which element should be influenced? For example, Table_1 or Button_1.

<Method> is an operation applied to the object specified on the left of the period. Ask yourself, what should be done with the element? The available methods depend on widget type. For example, data source objects provide methods to filter data, and visual components provide methods to modify visibility: setVisible, refreshData, or addItem.

<Arguments> is a comma-separated list of expressions. The passed expressions must match the requirements of the method. Ask yourself, which details are needed to do it? For example, Visibility = true, Key = DE, or Text = Germany.

Each statement ends with a semicolon (;).

In the example CH_TaxesPerMonth.getDataSource().setDimensionFilter("0CALYEAR","2018");

  • <Widget> CH_TaxesPerMonth
  • <Method>getDataSource and setDimensionFilter
  • <Arguments> 0CALYEAR and 2018

Use APIs in Scripting to Filter a Table Using a Button

Business Scenario: Your team makes a request to add buttons to the Taxes chart that will allow them to easily select the year 2018 or 2019 to view the data. They also want a button that they can simply click to reset the filters to show all the data.

This short video will walk you through the final story and scripting required.

Simulate the Steps

The practice exercise below simulates being in Advanced Mode in SAP Analytics Cloud and takes you through adding scripting to the buttons to create the final story shown in the demo video.

Task Flow: In this practice exercise, you will:

  • Add scripting to the buttons to filter by 2018, 2019, and show all data
  • Test the scripting in the story

Log in to track your progress & complete quizzes