Sisense dashboard script: Display alert box
- Lekha Mirjankar
- Jul 15, 2023
- 2 min read
Sisense dashboards can become even more powerful and user-friendly when you harness the capabilities of JavaScript scripting. In this tutorial, we'll go through the process of incorporating an alert box feature using Sisense dashboard script to display any message. We'll use the example of detecting multiple day selection in a filter and triggering an alert to enhance your dashboard's interactivity.
Step 1: Adding the widget script
Begin by opening your Sisense dashboard in the Edit mode. Add the following code into the dashboard's script editor.
dashboard.on('filterschanged', function(s, e) {
// Check if the specified filter exists and has multiple selected days
// Instead of Commerce.Date add your Table.Column name
if (
dashboard.filters.item('[Commerce.Date (Calendar)]', 'days') &&
dashboard.filters.item('[Commerce.Date (Calendar)]', 'days').jaql.filter.hasOwnProperty('members') === true
)
{
// If multiple days are selected
if (dashboard.filters.item('[Commerce.Date (Calendar)]', 'days').jaql.filter.members.length > 1)
{
// Display an alert
alert("Alert text here");
// Get the default date filter
let defaultFilter = dashboard.defaultFilters[0];
// Set the date filter to it's default state
dashboard.filters.update(defaultFilter, { refresh: true, save: true })
}
}
});
Step 2: Understanding the Code Logic
We use the dashboard.on('filterschanged', function(s, e) {...}) event handler to execute our code when the dashboard filter is changed.
The code checks if the specified date filter exists and has multiple selected days.
If multiple days are selected, an alert box is displayed to the user, which shows the alert message.
The date/day filter is reset to it's default filter state. (This gets executed after the user clicks "OK" on alert box)
Flow:
Check the condition (If true then) --> Display alert box --> Action after user clicks "OK" (optional)
Note:
Here, we have used the date filter as an example; but you can use any filter or condition that suits your requirement.
If you want to display the alert box every time the dashboard is initialized/loaded, then use the dashboard.on('initiliazed', function(s, e) {...}) event handler instead and remove all unnecessary conditions like so-
dashboard.on('initialized', function(s, e) {
// Display an alert
alert("Alert text here")
});
Step 3: Applying the Changes
After adding the script, click "Save" to apply the changes and refresh the dashboard. Now, whenever the condition is passed (if mentioned), the alert box will be displayed. After clicking "OK", if you have mentioned anything in the script, that will be executed.

GitHub link : https://github.com/lekhamirjankar/Sisense-scripts
Commentaires