Set token value by script

Contents[Hide]

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.

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
viewParameter.parameterValue.clearValues(); 
viewParameter.parameterValue.clearTokens();

// Create new token and set to "All"
var myToken = new dundas.data.ParameterToken({
  "caption": "All",  
  "id": dundas.constants.ALL_TOKEN_DEFINITION_ID
});

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

// Reset modified time to take precedence
viewParameter.invalidateParameterValueLastModifiedTime();

// Load changes
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);

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.

  • ALL_TOKEN_DEFINITION_ID: "All"
  • DEFAULT_TOKEN_DEFINITION_ID: "Default"
  • NULL_TOKEN_DEFINITION_ID: "Null" (only if your filter allows null)
  • NO_SELECTION_TOKEN_DEFINITION_ID: "No Selection"
  • OPEN_RANGE_BOUNDARY_TOKEN_DEFINITION_ID: "Open Range" (normally used for date filters)

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