Use APIs on Story Filter and Variables

In Optimized Story Experience, as a story developer, you can use script APIs related to story filters and variables to let story viewers change the visibility of the filter panel, set story filters and set story variables, for example.

Use APIs Related to Filter Panel

You can use the following APIs to let viewers show or hide the filter panel and check its visibility respectively:
Sample Code
FilterPanel.setVisible(bVisible: boolean): void
FilterPanel.isVisible(): boolean

Use APIs Related to Story Filters

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:
Sample Code
// only model already in the document is supported
Application.getFileDataSource(modelId: string): +FileDataSource
 
// account or measure member filter is not supported, API is align with UI
FileDataSource.setDimensionFilterWithHierarchy(dimension: string|+DimensionInfo, hierarchy: string|+HierarchyInfo, member: string|[string]|+MemberInfo|[+MemberInfo]|+TimeRange|[+TimeRange]|+FilterValue|[+RangeFilterValue])
 
FileDataSource.removeDimensionFilter(dimension: string|+DimensionInfo)
 
FileDataSource.getDimensionFilters(dimension: string|+DimensionInfo):[+FilterValue]
Note

Dimension and fixed date range filters are supported, while widget-level measure and dynamic date filter aren't supported by the APIs.

In addition, via the APIs you can let viewers create custom current date (CCD) input controls based on either calendar or fiscal time:
Sample Code
class CurrentDateTime {
   createCalendarDateTime(calenderTime: +CalendarTime): CurrentDateTime;
   createFiscalDateTime(modelId: string, dimension: string|+DimensionInfo/*time dimension*/, fiscalTime: +FiscalTime): CurrentDateTime;
}
 
// API to take effect
Application.setCurrentDateTime(ccd: CurrentDateTime);
 
// use case 1:(year)
var calenderYearCCD = CurrentDateTime.createCalendarDateTime({granularity: CalendarTimeGranularity.Year, year: 2014});
Application.setCurrentDateTime(calenderCCD);
 
// use case 2: (day)
var calenderDayCCD = CurrentDateTime.createCalendarDateTime({granularity: CalendarTimeGranularity.Day, year: 2014, month: 2, day: 20});
Application.setCurrentDateTime(calenderDayCCD);
 
// use case 3:(fiscalYear)
var ccdFiscalYear = CurrentDateTime.createFiscalTime("C5ULLISAVFR6N0HM0ZIVIIHURK", "Date_703i1904sd", {
    granularity: FiscalTimeGranularity.FiscalYear,
    fiscalYear: 2022
});
Application.setCurrentDateTime(ccdFiscalYear);
Here're the parameters for calendar time:
enum CalendarTimeGranularity {
   Year,
   HalfYear,
   Quarter,
   Month,
   Week,
   Day
}
class CalendarTime {
    granularity:  CalendarTimeGranularity,
    year: integer,                      // >= 0, for example, 2013     
    halfYear?: integer,                 // for example, 1..2
    quarter?: integer,                  // for example, 1..4
    month?: integer,                    // for example, 1..12
    week?: integer,                     // for example, 1..53
    day?: integer,                      // for example, 1..31 (day need to work together with month and year)
}
Here're the parameters for fiscal time:
enum FiscalTimeGranularity {
   FiscalYear,
   FiscalQuarter,
   Period,
   FiscalDay
}
 
class FiscalTime {
    granularity:  FiscalTimeGranularity,
    fiscalYear:integer,      // >= 0, for example, 2013
    fiscalQuarter?: integer, // for example, 1..4
    period?: integer,       // for example, 1..12
    fiscalDay?: integer,   // for example, 1..31 (fiscalDay need to work together with period and fiscalYear)
}

Use APIs Related to Story Variables

You can use the following script APIs to set, remove and get the story variables respectively:
Sample Code
FileDataSource.setVariableValue(variable: string|+VariableInfo, variableValue: string|number|+VariableValue|[+VariableValue], options?: +SetVariableValueOptions)
FileDataSource.removeVariableValue(variable: string|+VariableInfo)
FileDataSource.getVariableValues(variable: string|+VariableInfo):[+VariableValue]