on ‎2023 Dec 05 1:56 PM
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?
Request clarification before answering.
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(", "));brYou must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
| User | Count |
|---|---|
| 12 | |
| 9 | |
| 7 | |
| 5 | |
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.