Skip to Content
0
Former Member
Mar 26, 2015 at 08:06 AM

Filtering a data source by string variable

595 Views

Hello everyone,

We have two data sources which share the attribute "location". Both are based on BEx-Queries.

Data Source 1 contains all available locations, while data source 2 contains only a subset of locations. Our goal is to filter data source 1 by its location attribute so that it contains the same number of rows with the same locations as data source 2 (like an inner join).

As it is possible to filter a data source like this

DS_xy.setFilter("Dimension", ["member1", "member2", "member3", ... ]);

our idea was to use the following method:

1. Declare a string variable and an array of the members

var text = ""; //we also tried to use a global scripting variable

var array = DS_2.getMembers("Location", 1000);

2. Use a nested for-loop to read all the locations of data source 2 into the string

array.forEach(function(element, index) {

text = "\"" + element.externalKey + "\"";

array.forEach(function(element, index) {

text = text + ", \"" + element.externalKey + "\"";

});

});

3. Filter the data source by the generated string (which contains: "location1" , "location2", "location3", ...)

DS_1.setfilter("Location", [text]);

It doesn's work. We have checked the externalKey-format, which corresponds to the format of members in data source 1.

When I copy the string returned by variable "text" into the code like this

DS_1.setFilter("Location", ["location1", "location2", "location3"... ];

it works perfectly.

Can anyone help? Thank you in advance!

Christiane