Set filter value by script

Contents[Hide]

1. Overview

This article walks through how to set a parameter value using script. In the example shown below, the filter value is set on a click of a button control.

While script is not required to accomplish an interaction like this in Dundas BI, the purpose of this article is to demonstrate how you can perform this action using the API as part of your own custom functionality.

2. Set-up the dashboard

For this example, a relational table (non-OLAP) is used.

Relational Table
Relational Table

  1. Add a data visualization to the dashboard such as a table or chart. Drop a measure and dimension to the MEASURES and ROWS section of the Data Analysis Panel. In this example, a SLICER is used using the Country column.

    Data Analysis Panel
    Data Analysis Panel

  2. Add a member filter and connect it to your column. Take note of the View Parameter Script Name, which in this case is viewParameter1. For your first filter created on the dashboard, this is the default name, but you can rename if you choose.

    Filter Visualizations panel
    Filter Visualizations panel

    Take note also of the filter control name, which is parameterHierarchy1. Like the View Parameter, this is the default name for the first filter added, but you can rename this if you choose.

    Check the parameter script name
    Check the parameter script name

3. Determine the required script

  1. Add a button component and add the script debugger; in the button's Click action script. Refer to Writing scripts using browser developer tools for reference.

    Button click interaction script
    Button click interaction script

  2. View the dashboard.

  3. Select the filter value, e.g. "Japan".

  4. Click the button control to fire the Click action script.

    Firing the script
    Firing the script

  5. On the Console, type the script below (adjust the filter control name if necessary):

    parameterHierarchy1.control.parameterValue;

    Developer Tools' console
    Developer Tools' console

  6. Inspect the parameter's structure and the values, particularly the following:

    • hierarchyUniqueName = "Country"
    • LevelUniqueName = "Country.Regular"
    • uniqueName = "Japan.Country"

4. Add the Script

You can add this script to any action, such as a button's Click, on a dashboard's Load or Ready, on a parameter's Changed actions, etc. If you use the script in the Load actions, you should replace "this.parentView" with simply "this".

var viewParameter = this.parentView.control.getViewParameterByName("viewParameter1");
var filterValue = new dundas.data.MemberValue({
  hierarchyUniqueName: "Country",
  levelUniqueName: "Country.Regular",  
  uniqueName: "Japan.Country"
});

viewParameter.parameterValue.token = null;
viewParameter.parameterValue.values.length = 0;
viewParameter.parameterValue.values.push(filterValue);

viewParameter.invalidateParameterValueLastModifiedTime();
viewParameter.refreshAllAdapters();
// If setting the filter values for an embedded dashboard, 
// the following line of code should be used instead to refresh the adapters:
// viewParameter.refreshAllAdapters(null, this.parentView);

Add the script to a button's click actions
Add the script to a button's click actions

5. Test the script

  1. View the dashboard
  2. Select any filter value other than the one you're setting through script.
  3. Click the Button control to fire the script.

Result: The new filter value should be set:

Add the script in a button's click actions
Add the script in a button's click actions

6. See also

Dundas Data Visualization, Inc.
500-250 Ferrand Drive
Toronto, ON, Canada
M3C 3G8

North America: 1.800.463.1492
International: 1.416.467.5100

Dundas Support Hours: 7am-6pm, ET, Mon-Fri