Get filter value in script and assign to a label

Is there a way to get the current filter value and assign it to a label. I have my script as below but couldn’t get the filter value

var baseViewService = this.getService("BaseViewService");

var myFilter= baseViewService.currentView.control.viewParameters.filter(function(item) {

return item.name === "ParameterName";

})[0];

Label1.labelText = ??

The first question would be which filter you are using. Since you are asking about a value, I'll assume it's a numeric filter. The script to get that value will be something like

this.baseViewService.currentView.control.viewParameters[1].parameterValue.value

Hope it helps.

Thanks for the reply. I already tried this and this didn't help me Elia. My filter takes value as string. It takes values from a column and by default I have assigned a single string value to it. In the dashboard ready action, I am writing the script to display that filter value using the label. when I write the script as below it displays label as [object object].


label3.labelText = this.baseViewService.currentView.control.viewParameters[2].parameterValue.value;

In that case, the column is a hierarchy and you will have to get the unique name instead (it's inside the values array).


When you are working with a non-multi-level hierarchy, the unique name should be something like value.column, so you will have to use the JavaScript string split to get the value part.


Note that you should also replaced this.baseViewService.currentView with the script name of the filter control.


Will look something like this:

var uName = parameterHierarchy1.control.parameterValue.values[0].uniqueName;
var value = uName.split(".", 1);
label1.labelText = value;

You can use this support article to learn how to script with filters (parameters) but aside from using a script, you can also consider using a data label that shows the hierachy of values that your filter contains. Then simply connect the filter to that data label as well so it updates both your visuals and that data label.

The above solution do not work for me as I haven't created any hierarchy for that column and it is directly pulling the values from one of the data cube column and it is present as silcer in my visualization as I am filtering values. I have created a view Paramter for this column and passing the values for it from a different different visualization. This works perfectly fine. But when I pass the values to the view parameter I would like to capture it and display on a label for the user.

There is no need to create a custom hierarchy for this column. Simply add a new data label, drag the column from the data cube onto this data label and cnnect the filter you already have to that data label column.

You do not need to create any hierarchy. The column is treated as a single-level hierarchy. If you did have a custom hierarchy, the script would be much more difficult as the unique name would likely not contain the actual value.


With that said, judging from your descriptiong, the solution Ariel is providing seems to be a lot more fitting and easier to maintain.

Thank Ariel & Elia. This helped me.



Hi. Regarding your question, I have the same problem but would like to get a date filter value and assign it to a text label, preferably only the month and year.

The alternative is to get the month and year from a bottom axis of a chart and asign it to the text label. Any ideas? Thanks in advance!

The solution Ariel provided would work in this case as well. Since it's a data label instead of a regular label, you will also be able to format the data text as you see fit.