Skip to Content
1

How can i write on name buttons dinamically by datasource for setting filters on a histogram?

Nov 30, 2016 at 12:21 PM

140

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

6 Answers

Mustafa Bensan Nov 30, 2016 at 02:32 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Nov 30, 2016 at 06:10 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

0
Lorenzo Te
Dec 01, 2016 at 02:11 AM
0

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Lorenzo,

I am running DS 1.6 SP3 and I do not see a name attribute, just the ones below:

Can you clarify?

Thanks,

Mustafa.

getmembers.png (22.3 kB)
0

Hi Mustafa,

Sorry, I meant using the key (externalKey or internalKey) value.

0
avatar image
Former Member Dec 01, 2016 at 12:40 PM
0

Hi,

it doesn't work!! I do not know why! it doesn't make sense!

var myButtons = [BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4];
var rows = BRAND.getMembers("dimension", 4);
rows.forEach(function(element, index) {  
var myRow = myButtons.pop();  
BUTTON_3.setText(element.text);
});

no change on the button!


button-name.png (1.5 kB)
blank-button.png (1.1 kB)
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Dec 01, 2016 at 01:41 PM
0

I checked to move the code from the Global script to an "on select" areaof a crosstab, and i get this:

No attribution?

Maybe is related to hierarchy?

Why i cannot see this "senza attribut" in the global script?

Marco


Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Dec 01, 2016 at 01:57 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

1