Set token value by script


1. Overview

This article walks through how to set a token value using script. In the example below, the filter value is set to All when a button is clicked. You can refer to Set filter value by script for the steps for setting up the dashboard and filter used in this example.

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 sample: Set range number parameter token

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 to the button's Click actions.

Add the script
Add the script

var viewParameter = this.parentView.control.getViewParameterByName("viewParameter1");

// Reset the view parameter

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

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

// Reset modified time to take precedence

// Load changes
viewParameter.refreshAllAdapters(null, this.parentView);
// (Pass the current view in case it's embedded inside another)

Here is a list of tokens with predefined IDs you can use as done above. Note that not all are applicable for the member filter used in this sample. Any token can be used once you find its ID - see Modify a filter / view parameter using scripting for more details and examples.

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

The ID of any token can found from the Tokens screen in Administration by selecting one and clicking Details in the toolbar.

4. Test the script

  1. Choose Sandbox View in the toolbar to test the dashboard without saving changes made while viewing.
  2. Select any filter specific value (e.g., "Canada").
  3. Click the button.

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.
400-15 Gervais Drive
Toronto, ON, Canada
M3C 1Y8

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