cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Change Selection to String

NPH
Participant
0 Likes
3,236

Hi,

I am using an optimised story and want to show the selection from a bar chart as dynamic text on the next page.

Currently, the way I get the selection for my filters is:

selection = this.getSelections();

This works for applying the filters. However I cannot use this as dynamic text. For that I need the type to be string.

Is there a way I can use the first selection as a string or something similar?

Accepted Solutions (1)

Accepted Solutions (1)

eeddggaarr
Contributor

Hi Nathan,
if you want to print selected dimension members on the same page you can use smthg like this:

var selection = this.getSelections();

var sel_array = ArrayUtils.create(Type.string);
for (var i = 0; i < selection.length; i ++) {	
	sel_array.push(selection[i]["your_dimension_of_interest"]);
}
var sel_str = sel_array.join(", ");

Text_1.applyText(sel_str);

if you want those members written on another page than you must use a global variable (e.g. ScriptVariable_1) - maybe that will change in the future when scripting can be used without page dependency.
code for your bar chart onSelect:

var selection = this.getSelections();
ScriptVariable_1 = ArrayUtils.create(Type.string);
for (var i = 0; i < selection.length; i ++) {	
	ScriptVariable_1.push(selection[i]["your_dimension_of_interest"]);
}

ScriptVariable_1 is defined as:

the script for Page_2 (I have used onActive):

Text_2.applyText(ScriptVariable_1.join(", "));
br
edgar
NPH
Participant
0 Likes

eeddggaarr

Thank you for this, this is exactly what I am looking for.

As a little bonus, is it possible to display the description instead of the ID?

eeddggaarr
Contributor

Hi Nathan,
quick and dirty - maybe possible without a second for loop.

with getResultSet you can retrieve more details from your chart without calling your backend.
in the last line "ScriptVariable_2.push(resultSet[i]["your_dimension_of_interest"].id" you can replace .id with e.g. .description

ScriptVariable_1 can be changed into a local variable => it is best practice not to use too many global variables.

var selection = this.getSelections();

ScriptVariable_1 = ArrayUtils.create(Type.string);
for (var i = 0; i < selection.length; i ++) {	
	ScriptVariable_1.push(selection[i]["your_dimension_of_interest"]);
} ScriptVariable_2.splice(0,ScriptVariable_2.length); var resultSet = Chart_1.getDataSource().getResultSet({"your_dimension_of_interest": ScriptVariable_1});
for (i = 0; i < resultSet.length; i++) { ScriptVariable_2.push(resultSet[i]["your_dimension_of_interest"].id);
}<br>

br
edgar

Answers (0)