cancel
Showing results for 
Search instead for 
Did you mean: 
JeremyFriedel
Sisense Team Member
Sisense Team Member

Ensuring Accurate PDF Export Headers When Programmatically Modifying Dashboard Filters in Sisense

When working with Sisense dashboards, programmatically modifying filters upon dashboard load via dashboard scripts for a specific user or circumstance is possible. However, an issue can sometimes occur when exporting these dashboards to PDF immediately after such modifications: the filter header displayed at the top of the exported PDF displaying the current dashboard filter state may not accurately reflect the current state of the dashboard filters. This article explains the cause of this issue and presents a solution to ensure that PDF exports display the correct filter information in the header.

If this issue is not currently occurring, then the existing custom widget or dashboard script does not need to be modified, this step is only required in certain specific circumstances.

Inconsistencies in PDF Filter Headers

Programmatic modifications to dashboard filters during the initial load may not be fully registered in the dashboard's state when an export to PDF is initiated immediately. If the dashboard is exported before any manual interaction, such as refreshing or adjusting filters, the PDF's filter header might display outdated or incorrect filter information. This occurs because the dashboard's internal state and the visual representation of filters may not be fully synchronized immediately after the programmatic changes. The export function relies on the dashboard's state at the time of export, and if this state hasn't been properly updated to include the new filters, the PDF will reflect the previous filter settings.

No Filters Visible In PDF HeaderNo Filters Visible In PDF Header

 

Filter Visible in PDF HeaderFilter Visible in PDF Header

 

Solution: Updating the Dashboard State to Update PDF Filter Header

To resolve this issue, explicitly updating the dashboard's state after programmatically modifying the filters ensures that all components of the dashboard, including the export functionality, are aware of the current filter settings. By adding the following line of code after the filter modifications, the dashboard is forced to update its state to include the new filters:

prism.activeDashboard.$dashboard.updateDashboard(prism.activeDashboard, ['filters']);

Explanation

  • prism.activeDashboard: Refers to the currently active dashboard instance. The prism object is documented here.
  • $dashboard.updateDashboard(): A method that updates the dashboard's state.
  • Parameters:
    • First Parameter (prism.activeDashboard): The dashboard instance to update.
    • Second Parameter (['filters']): An array specifying which parts of the dashboard to update; in this case, the filters.

By specifying ['filters'], only the filters are updated, which is efficient and avoids unnecessary updates to other dashboard components.

Implementation Steps

  1. Modify Filters Programmatically: Ann existing script to change the dashboard filters as required upon loading.

    dashboard.filters.$$items[0].jaql.filter.members = ["Current User"]
  2. Update the Dashboard State: Immediately after modifying the filters, add the update line.

    // Update the dashboard to reflect filter changes
    dashboard.$dashboard.updateDashboard(prism.activeDashboard, ['filters']);
  3. Export to PDF: Proceed with exporting the dashboard to PDF. The filter header should now accurately display the current filter settings.

Conclusion

By ensuring the dashboard's state is updated after programmatic filter changes, any exports or other state-dependent operations will reflect the true current state of the dashboard. This simple addition to the script can prevent confusion and ensure that exported PDFs accurately represent the intended data and filters.

By following the steps outlined, Sisense dashboards will accurately reflect programmatic filter changes in exported PDFs, providing clarity and consistency.

Related Content: 

Docs: https://docs.sisense.com/main/SisenseLinux/customizing-sisense-using-code.htm

Academy: https://academy.sisense.com/master-class-advanced-dashboards-with-plug-ins-and-scripts

Rate this article:
(1)
Version history
Last update:
‎12-09-2024 02:14 PM
Updated by: