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
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.
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:
Conclusion
Help Documents:
Please refer below SAP help documents:
- Use APIs on Story Filter and Variables (Optimized) | SAP Help Portal
- Optimized Story Experience API Reference Guide Version 2026.8
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.