Set Parameter Value

Hi,


I think I'm missing something here.


I created a viewParameter and assigned it to the correct column in the data to filter.


The column is bit value (true/false). I wanted to create a button that toggles this value but it doesn't seem to be working.


Here's the script I'm using. I'm pretty sure it's the second last line that's giving me issues but I just don't know what to change it to. Any help would be appreciated. Thanks!



// Get the parent view.
var parentView = this.parentView;

// Get the view parameters.
var viewParameter = parentView.control.viewParameters;

// Using the library, get the view parameter based on it's name --this.parentView.
var viewParameter = this.parentView.control.getViewParameterByName("viewParameter2");

// Remove all values from the parameter value
viewParameter.parameterValue.clearValues();

viewParameter.parameterValue.values = "True";
viewParameter.refreshAllAdapters();

Try putting this line right after setting it and beofre the refresh


viewParameter.invalidateParameterValueLastModifiedTime();


See sample

Hi Daniel,


You can try the below mentioned script:

// Get the parent view.

var parentView = this.parentView;

// Get the view parameters.

var viewParameter = parentView.control.viewParameters;

// Using the library, get the view parameter based on it's name --this.parentView.

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

//Build the member value

var myMemberValue = new dundas.data.MemberValue({

"hierarchyUniqueName": "<Name of your hierarchy>",//This will be the name of your hierarchy

"levelUniqueName": "<Name of your level>",//This will be the name of your hierarchy

"memberKind": "Regular",

"uniqueName": "<Value - In this case TRUE>.<Name of your hierarchy>" //This will be the name of your hierarchy

});

viewParameter.parameterValue.clearTokens();

viewParameter.parameterValue.clearValues();

viewParameter.parameterValue.values.push(myMemberValue);

viewParameter.invalidateParameterValueLastModifiedTime();

viewParameter.refreshAllAdapters();



The problem with the script that you are trying to use is the method of assigning values to the filter in your second last line. The section in the below mentioned support article specifies that to assign a value to a filter we will need to create a script like the one above (var myMemberValue = new dundas.data.MemberValue):

https://www.dundas.com/support/support-center/support-articles/scripting/modify-a-filter-/-view-parameter-using-scripting#h5-4-collectionmember


You will also need to clear token (viewParameter.parameterValue.clearValues()) along with values before pushing the new value to the filter and will also need to invalidate the filter’s last modified time after pushing the value to make sure the new value is reflected (viewParameter.invalidateParameterValueLastModifiedTime()).


You will also need to add the values to the "<Name of your hierarchy>" and <Name of your level> by checking its values in the chrome development tool:

https://www.dundas.com/support/support-center/support-articles/scripting/writing-scripts-using-browser-developer-tools


I hope this helps. :-)

1 Like

You can certainly use a script to control your action but there is also a rather simple way to avoid the need to script your selected parameter value. The following video demonstrates the steps to setup a checkbox to control your filter values with no script. The same approach can be used with many other components including radio buttons, drop-down lists and more.

That worked!

Thanks Pankaj!