Dynamic slicer definition
Covers report slicer dynamic data JavaScript object definition and its format.
The SmartDash interface allows the report designers to define what items in specific report slicers should be pre-selected dynamically based on variables like the current date etc.
Steps to define dynamic slicer data
Open the JavaScript editor
Go to Manage > Reports and click on the name of the report for which you want to edit the dynamic slicer data definition.
Edit the displayed JavaScript object
The editor opens the JavaScript object that belongs to the clicked report. Edit it as required following the format described below in this document in the topic The format of the JavaScript object defining dynamic slicer slicer pre-selections.
Save the updated JavaScript object
You don't need to roll forward the version of the report after editing the JavaScript definition object.
The JavaScript object format
Below we will describe the format of the JavaScript object in steps.
High level format
The basic high-level format of the JavaScript object defining dynamic slicer pre-selections has the following hierarchy slicers > [report page name] > [slicer name] like so:
var reportDynamicDataDefinition = {
slicers: { // A static name
page1Name: { // Your report page title converted to a property name
slicer1Name: { // Your slicer title converted to a property name
// "Slicer format" (see below) here
},
slicer2Name: {
// ...
} //,
// (more slicers here)
},
page2Name: {
slicer1Name: {
// ..
}
} //,
// (more pages here)
}
}
Page and slicer names
Important:
All the slicers which you wish to reference from the dynmic data JavaScript object must have titles!!!
The property names of page and slicer objects defined in the JS object above are computed with the following rules:
- The whole name is converted to lower case.
- The first letters of all words except the first one are capitalized.
- All spaces are removed.
So as an example, having a page name like "Page 1 name" would result in the "page1Name" property name as in the example above going through the following transformation:
"page 1 name" (step 1) -> "page 1 Name" (step 2) -> "page1Name" (step 3)
Important:
From the above it should be clear that if you change the title of a page or the title of a slicer you must update the name of the matching object property name in the JavaScript definition to reflect that change.
Complete format example
To see an example of a complete JavaScript definition object format see this page.
For a complete list of available properties if the slicer definition objects go here.
Slicer object format
Basic
{
format: "MMM yyyy",
multiselect: true,
selectConditions: "(FY(Now()) >= value < GetDate(Year(Now()), Month(Now()), 1)) || (Year(value) > 2030)",
expression: "DatePeriods({period: 'M', startDate: DateAdd('y', Now(), -3, null, 1), endDate: Now()})"
}
The basic required property is called selectConditions and defines one or more conditions which, when matching a value in the list, will result in pre-selecting that list value.
The value in this list is a single string which is expected to contain:
- At least once the keyword
value. This keyword represents the value from the list of slicer values that will be tested. The value in the list will be pre-selected if the result of the expression after evaluation istrue. - Usually a combination of one or more allowed functions.
- One or more comparison operators:
<, >, =, !=, <=, >= - One or more logical operators
&&, || - Grouping parentheses
(, ) - Single-quoted strings
'some string'
No other functions or control characters are allowed in these string values.
Only the selectConditions property is really needed. Other properties may be needed depending on the circumstances. In the example given above the slicer is a date slicer which should allow multiple selections and thus the multiselect property is defined and set to true. Furthermore, because the list contains dates with a specific format the format must be specified in order to correctly match those dates with the selectConditions. The expression returns an array of dates which may match (some of) the dates that are already contained in the source table for the slicer, in which case it would not add such dates, but it would add to the slicer list and select any dates that are missing from the underlying source table.
Please see the complete list of available object properties here.
Full
An example of a full slicer dynamic data definition would be:
{
target: {
table: "Reporting Year",
column: "Reporting Year End"
}, // IMPORTANT: If specified the table name and column name must be matching
// exactly to the specification in the report as they are used to create a property
// name on the base of which matching is done.
name: "Reporting Year End", // For purely identification purpose.
description: "", // Same as "name".
format: "d MMMM",
multiselect: false,
selectConditions: "value == DateAdd('d', DateAdd('M', DateAdd('y', FY(Now(), true), -1), 13), -1)",
values: [ // Will test the "condition" one after another until one is true.
// Overrides properties in the main definition (like name, description, type etc.).
{
name: "LastFY if current less than 2 months",
descr: "Calculates the start date of the the last financial year if we are les than 2 months into the current financial year.",
condition: "FY(DateAdd('M', Now(), -2)) < FY(Now())",
expression: "DatePeriods({period:'M', startDate: DateAdd('y', FY(Now()), -1), arraySize: 12, onlyIfAlreadyPassed:, true, day: 'end'})",
selectConditions: "value == DateAdd('d', DateAdd('M', DateAdd('y', FY(Now(), true), -1), 7), -1)"
// OPTIONAL: This overrides the parent definition's select condition.
}, {
name: "CurrentFY",
descr: "Returns the first date of a financial year.",
condition: null,
expression: "DatePeriods({period:'M', step: 1, startDate: FY(Now()), endDate: FY(Now()), fullMonths: false, ceiling: true})"
}
]
}
The values can also be and array of arrays (as opposed to an array of objects) in which case the sub-arrays should have one to three elements where the first element is the value itself (an absolute value or an expression), the second is a boolean specifying whether or not the first value is a pure string or an expression (if true) and the third should be true if the value should be pre-selected.
If the boolean values are omitted they default to false.