on 11-30-2016 12:21 PM
I have created a script (in GLOBAL SCRIPT area) to retrieve data from a BW data source with hierarchy.
In order to populate text name of five buttons that filters an infochart with a "setfilter" function.
I'm using an array (rows) to get 4 members
For testing I pop out a text from the array and put it in a text area TEXT_1
After that i use forEach and set di name button of BUTTON_1 only to see if the name button change
here is the code:
/*dim is dimensione name */
var rows = BRAND.getMembers("dim", 4);
rows.pop().text;
TEXT_1.setText(rows.pop().text);
/*put text to button_1 */
rows.forEach(function(element, index) {
if (index == 3){
BUTTON_1.setText(element.text);
BUTTON_1.setText(rows.pop().text);
}
});
Nothing happens.
Thanks
Marco
Hi,
doing other tests,
I succeed to read something, but this foreach method seems that it does not read the BW hierarchy.
I also use "activatehierarchy on the data source!
Marco
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marco,
Sorry, I missed that important detail in your original question that you are using a hierarchy on the dimension. Unfortunately, getMembers() does not support reading hierarchies. It will only return the dimension members. There is no way to iterate through a hierarchy via scripting with standard Design Studio functionality.
Regards,
Mustafa.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mario,
Have you checked what are the actual members that are being extracted using the getMembers method?
Instead of the text attribute, maybe you can try the name attribute (element.name) instead. It may be possible that the members that you are getting have blank text values.
Regards,
Lorenzo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it doesn't work.
I deleted what the code begore forEach and move and change index == 3 in index == 1, after that i move
TEXT_1.setText(rows.pop().text);
inside the foreach, after button code but no change see on the browser!
Marco
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marco,
Please ignore my previous comment. Here is a solution that worked for me:
var myButtons = [BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4];
var rows = BRAND.getMembers("dim", 4);
rows.forEach(function(element, index) {
var myRow = myButtons.pop();
myButton.setText(element.text);
});
By using an array of buttons you can apply a dynamic approach to setting button texts in your loop instead of hardcoding multiple if then statements.
Let me know how you go,
Mustafa.
Hi Marco,
Prior to the forEach() loop you are executing 2 pop statements, which removes the last two array elements, leaving the rows array with just two elements, with index 0 and 1. Therefore, the condition if (index == 3) is never met, so the button text is not changed.
Regards,
Mustafa.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.