Set token value by script


1. Overview

This article shows you how to set a token value by script. For example, you may want to set a filter to "All" by script. The basic idea is to add a script (JavaScript code) that will change the filter value when the interaction is fired. A sample is shown below, wherein the filter value is set to "All" on a click of a button control.

You can check the sample Set filter value by script on how to set-up the dashboard and filter.

2. Check applicable token values

You can view the dashboard and check the applicable token values. In this case, All and Default.

Applicable token values
Applicable token values

3. Add the Script

Add the script on the Button Click interaction.

Add the script
Add the script

var baseViewService = this.getService("BaseViewService");
var viewParam = baseViewService.currentView.control.viewParameters.toEnumerable().first(function(vp) {
    return === "viewParameter1";

// Reset the viewParameter

// Create new token and set to "All"
var myToken = new{
  "caption": "All",  
  "id": dundas.constants.ALL_TOKEN_DEFINITION_ID

// Assign the newly created token
viewParam.parameterValue.token = myToken;

// Reset modified time.

// load changes
//if you are setting the token value for an embedded dashboard
//then the following line of code should be used instead to refresh the adapters

//optional - since setting token value by script will not refresh the previously
//selected boxes, you can refresh/uncheck them by:

/*** Script Ends Here ***/

Here are the list of token values. Note that not all are applicable for the member filter used in this sample.

  • NULL_TOKEN_DEFINITION_ID : "Null" - only if your filter allows null
  • OPEN_RANGE_BOUNDARY_TOKEN_DEFINITION_ID : "Open Range" - normally used for date filters

4. Test the script

  1. View the dashboard
  2. Select any filter specific value, e.g. "Canada".
  3. Click the Button control to fire the script.

Result: The new filter value should be set to "All".

Click button to fire the script
Click button to fire the script

5. 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