Set filter value by script


1. Overview

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

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.

Script Library samples: Filter and Parameter

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 under Measures and a hierarchy to Rows in the Data Analysis Panel. In this example, the Country column is also added to Slicers.

    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 it 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

The script to use depends on the type of value you want to set and how you determine its value. You can find details and examples of various parameter types in the article Modify a filter / view parameter using scripting.

Below, we will walk through how to find a hierarchy member's information interactively and use it to set a CollectionMemberValue type parameter.

  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):


    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{
  hierarchyUniqueName: "Country",
  levelUniqueName: "Country.Regular",  
  uniqueName: "Japan.Country"

viewParameter.parameterValue.token = null;
viewParameter.parameterValue.values.length = 0;

// 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:
Phone: 9am-6pm, ET, Mon-Fri
Email: 7am-6pm, ET, Mon-Fri