416.467.9100 | Dundas Data Visualization | Login
Welcome Guest
Dashboard v5.0

This site makes extensive use of JavaScript.

Please enable JavaScript in your web browser and reload the page before proceeding.

Save and Restore Parameter Values

Hide navigation
RSS
Modified on Thu, 20 Mar 2014 05:23 PM Categorized as Parameters, Script Library, Scripting
Dundas Dashboard Script LibraryPrevious


Overview

This example shows how to use scripting to save and restore the parameter values. For example, users might want select certain parameter values on a dashboard, and then drill down to another dashboard (or stay on the same dashboard and change parameter values as in this sample). When they return to the original dashboard, they want to see the original parameters selected prior to the drill down.

Tip: This article also shows how to use:
  • the Globals property of the script services object to store and recall your own global variable values.
  • the GetCurrentParameters and SetCurrentParameters property of the script services object to get and set parameter values.
  • the SerializeToString method. This will convert the parameter collection into a text format. This is useful when you want to build up the dashboard URL by script. For more information on the URL parameters, refer to the Using Viewer.aspx article, under Dd_Parameters.


Setup

Dashboard

For this example, use the Sales Dashboard that is included with the Sonatica Performance samples (which you can install via the Deployment Center). Or, use any other dataset of your choice.

The Sales Dashboard.

The Sales Dashboard.


Steps

  1. Edit the Sales Dashboard. You can also make a copy if you prefer to keep the original dashboard.
  2. Add a Button control to the dashboard and set its Text property to Save Params.
  3. Add another Button control to the dashboard and set its Text property to Restore Params.
    The Sales Dashboard.

    The Sales Dashboard.



Script

Option 1: Using ParameterInfoCollection

Button1.Click

Next, add the following script code for the Click interaction of the Save Params button. The script saves all the parameter values currently selected into a global variable.

ParameterInfoCollection params = new ParameterInfoCollection(); 
params = services.GetCurrentParameters(); //get all the parameter values
if (services.Globals.ContainsKey("Dashboard1_Params"))  // Check if the key is present
{
    services.Globals.Remove("Dashboard1_Params"); 
} 
services.Globals.Add("Dashboard1_Params", params); //Stores the value into the global variable.

Button2.Click

Add the following script code for the Click interaction of the Restore Params button. The script loads the saved parameter values from a global variable. You can also place this script on the Dashboard's Load Interaction if you need to restore the parameters on load of the dashboard.

ParameterInfoCollection params = services.Globals["Dashboard1_Params"]; //retrieve stored value
services.SetCurrentParameters (params); //sets the parameter values

Option 2: Script using SerializeToString()

Button1.Click

string s = services.GetCurrentParameters().SerializeToString(); //get all the parameter values and convert to string
if (services.Globals.ContainsKey("Dashboard1_Params"))  // Check if the key is present
{
    services.Globals.Remove("Dashboard1_Params"); 
} 
services.Globals.Add("Dashboard1_Params", s); //Stores the value into the global variable.

Button2.Click

string params = services.Globals["Dashboard1_Params"]; //retrieve stored value
services.SetCurrentParameters(ParameterInfoCollection.Parse(params)); //sets the parameter values

Testing

To test the example:

  1. View the dashboard and change the parameter values.
  2. Click the Save Params button.
  3. Change again the parameter values.
  4. Click the Restore Params button and observe the previously saved parameter values are restored.

Related topics

About Dundas | Contact Us Follow us on Twitter! | Privacy Statement | Report Site Issues

Copyright © 2009-2014 Dundas Data Visualization, Inc.