cancel
Showing results for 
Search instead for 
Did you mean: 

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

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

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

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

MustafaBensan
Active Contributor

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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!

0 Kudos

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

MustafaBensan
Active Contributor
0 Kudos

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.

0 Kudos

Hi Mustafa,

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

Former Member
0 Kudos

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

MustafaBensan
Active Contributor
0 Kudos

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.

MustafaBensan
Active Contributor
0 Kudos

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.