Data and Analytics Blog Posts
cancel
Showing results for 
Search instead for 
Did you mean: 

While working on a recent SAP Analytics Cloud (SAC) requirement, I needed to dynamically set a story-level period filter to the current period using scripting. Although the requirement seemed straightforward, I found it surprisingly difficult to locate consolidated information on the APIs available for interacting with Story Filters. I explored multiple blogs, documentation pages, and community discussions, but most resources focused on widget-level filtering or general scripting concepts rather than story-level filter management.

During this journey, I came across a set of powerful Story Filter APIs that significantly simplified the solution. Since these APIs are not widely discussed and can be extremely useful in many real-world scenarios, I wanted to share my learnings through this blog. My hope is that this article helps fellow SAC developers quickly identify the right APIs and save the time and effort I spent researching them.

Introduction

While configuring story filters through the UI is straightforward, many SAC developers are unaware that story filters can also be accessed and manipulated through scripting APIs. This opens up possibilities for dynamic navigation, filter synchronization, user-specific personalization, and automated filter updates.

You can use script APIs related to story filters, which are applied to all widgets with the same data source across pages. The APIs also work for linked analysis applied to All Widgets in the Story. You can use the following script APIs to set, remove and get the story filters respectively:

// Only model already in the document is supported.

Before reading or updating story filters, obtain the file data source reference. Use control plus space tab to get list of data sources used in the story.

Application.getFileDataSource(modelId: string): +FileDataSource

// Account or measure member filter is not supported. The API is aligned with UI.

1) FileDataSource.removeDimensionFilter(dimension: string|+DimensionInfo)
2) FileDataSource.getDimensionFilters(dimension: string|+DimensionInfo):[+FilterValue]

3) FileDataSource.setDimensionFilterWithHierarchy(dimension: string|+DimensionInfo, hierarchy: string|+HierarchyInfo, member: string|[string]|+MemberInfo|[+MemberInfo]|+TimeRange|[+TimeRange]|+FilterValue|[+RangeFilterValue])

For the setDimensionFilterWithHierarchy API:

  • The hierarchy parameter is mandatory. If there's no hierarchy in the dimensions, use Alias.FlatHierarchy for the parameter.
  • Dimension and fixed date range filters are supported, while widget-level measure and dynamic date filter aren't supported.
  • TimeRange isn't supported for user-managed date dimensions.

Examples

1) To clear a story filter:

Syntax: Application.getFileDataSource.removeDimensionFilter(dimension: string|+DimensionInfo)

Ex: Application.getFileDataSource("FILE_ID").removeDimensionFilter("Region");

2) To get filter values currently selected:

Syntax: Application.getFileDataSource.getDimensionFilters(dimension: string|+DimensionInfo):[+FilterValue]

Ex:  Application.getFileDataSource("FILE_ID").getDimensionFilters("Region");

3) To change story filter with single or multiple values (with flat hierarchy).

Syntax: Application.getFileDataSource.setDimensionFilterWithHierarchy(dimension: string|+DimensionInfo, hierarchy: string|+HierarchyInfo, member: string|[string]|+MemberInfo|[+MemberInfo]|+TimeRange|[+TimeRange]|+FilterValue|[+RangeFilterValue])

Ex: 

To set single value:

Application.getFileDataSource("FILE_ID").setDimensionFilterWithHierarchy("Region",Alias.FlatHierarchy,"EMEA");
 
To set multiple values:
Application.getFileDataSource("FILE_ID").setDimensionFilterWithHierarchy("Region",Alias.FlatHierarchy,["EMEA","APJ"]);
 

Conclusion

Story Filter APIs are a powerful addition to the SAC developer toolkit, enabling greater control over filter behavior and user interactions. By understanding how to access and manipulate filters programmatically, developers can create more dynamic, user-friendly, and business-driven analytics experiences. As organizations increasingly demand personalized and interactive dashboards, these APIs become essential for building next-generation SAP Analytics Cloud solutions.
 

Help Documents:

Please refer below SAP help documents: