Skip to Content
avatar image
Former Member

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Nov 30, 2016 at 02:32 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 30, 2016 at 06:10 PM

    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

    Add comment
    10|10000 characters needed 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.

  • Dec 01, 2016 at 02:11 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

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

    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!

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 01, 2016 at 01:41 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 01, 2016 at 01:57 PM

    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

    Add comment
    10|10000 characters needed 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.