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.
3. Add the script
Add the script to the button's Click actions.
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(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.
- 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
- Choose Sandbox View in the toolbar to test the dashboard without saving changes made while viewing.
- Select any filter specific value (e.g., "Canada").
- Click the button.
Result: The new filter value should be set to "All".