cancel
Showing results for 
Search instead for 
Did you mean: 

Loop List using API Methods

former_member402770
Participant
0 Kudos

Hi All,

My Bex Query Structure(With No KF'S) :

                                  

PRODUCTS ID         PRODUCTS NAME           Words1                 Words2

  1                            wax                                  asdsad                  wrffvbv

  2                            lighter                               sadadas                rgergbg

  3                            candle                              asdasds                wvvxdsd

In DS 1.3, i am stuck up in the below steps itself.

var arr_products = DS_1.getMembers("PRODUCTS", 30);   

var arr_words1 = DS_1.getMembers("Words1", 30);

var arr_words 2 = DS_1.getMembers("Words2", 30);

I got the values to get stored in array from above.

I am trying to achieve like below. Get the list in an array and loop over that array and concatenate the text values .

Expected Output like below in ListBox when selection of wax and lighter in product dimension filter :

wax

asdsadwrffvbv   < - Concatenate both words and show as one word

lighter                          

sadadasrgergbg   < - Concatenate both words and show as one word    

Hope it should be understandable for everyone and need your solution guys.

Thanks,

Dinya. 

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Dinya,

Try using the following script in your Dimension Filter.

var arr_words1=DS_1.getMembers("Words1", 30);

arr_words1.forEach(function(element1, index)

{

 

  DS_1.setFilter("Words2", element1.internalKey);

  var arr_words2=DS_1.getMembers("Words2", 30);

  arr_words2.forEach(function(element, index)

     {

        LISTBOX_1.addItem(element1.internalKey+ " " +element.internalKey, element1.text+" " +element.text);

       });

});

Let me know if this works.

Regards,

Anuraag

former_member402770
Participant
0 Kudos

Anuraag,

  Thanks but there are two levels of dimension filter One is Company Code represented in the form of KF's which has UID in Drop Down and other is Product Dimension Filter.

I tried the above script for dimension filter like you mentioned..

The words got concatenated on applying Product Dimension Filter but there is one more level above is Company Code Drop down. So the scenario is first iam choosing an KF in Company code and then applying ALL/multiple selection item in Product dimension filter where then these words has to be concatenated. Currently the words gets concatenated based on Product Dimension filter, but it has to do starting from drop down company code ALL/single selection and then this dimension filter application after then words should get concatnated

Filter Panel Input:

Company Code Drop down

Product Dimension filter

Load Button

ListBox Output on selection of above filters:

wax

asdsadwrffvbv  

lighter                          

sadadasrgergbg 

Answers (1)

Answers (1)

former_member402770
Participant
0 Kudos

Dear All&Anuraag,

Tried to build an requirement in DS 1.3.

1)  I have one dimension filter named Product in my filter Panel and output display component as ListBox.

2) Tried to get to display like below in List Box which is my output to achieve:

Product 1

  Word1Word2

Product 2

  Word3Word4

3) First i selected an Product 1, Product 2 from Product dimensional Filter, so ListBox Displayed like below based on the selected product after writing an script on Apply Product Dimension Filter.

Product 1

Product 2

4) Now i tried to display Concatenated Word for selected Products. So written an script like anurag mentioned in Product On Apply Dimension Filter:

var arr_words1=DS_1.getMembers("Words1", 30);

arr_words1.forEach(function(element1, index)

{

 

  DS_1.setFilter("Words2", element1.internalKey);

  var arr_words2=DS_1.getMembers("Words2", 30);

  arr_words2.forEach(function(element, index)

     {

        LISTBOX_1.addItem( element1.text+element.text);

       });


});


Below output now in ListBox is:

Product 1

Product 2

Word1Word2

Word3Word4

But My Expected Output in ListBox is:

Product 1

  Word1Word2

Product 2

  Word3Word4

Tried achieving above output to write an On Apply script in Product Dimension Filter with same formatted output like above, but iam missing something here..

Thanks,

- Dinya.

IngoH
Advisor
Advisor
0 Kudos

Hello Dinya,

so you are receiving values from 3 different characteristics and it looks like you want to create some kind of hierarchical display ?

Have you thought about actually creating the hierarchy already in BW ? That would make things a lot easier as you would not have to go through all the scripting.

In case that is not an option then you would have to create arrays for all characteristics and basically load the members of each characteristic into each array. You wanna do that for all characteristics as otherwise you might lose the order of values.

Could you provide a little bit more background on the actual requirement here as it sounds to me that you trying to create something in Design Studio with lots of scripting that might be very easy achievable if you solve it in BW already.

regards

Ingo Hilgefort

former_member402770
Participant
0 Kudos

Hi Ingo,Anuraag and All,

   You are exactly right, the requirement actually looks like an hiearchial display with 3 different characteristics, but actually the Words Characteristics are not subtype of Product, so would like todo this in scripting basically what you mentioned "you would have to create arrays for all characteristics and basically load the members of each characteristic into each array" to look like what the expected output from my above post.

This should be achieved in Design Studio which iam trying to do like the expected output. Would appreciate for any ideas as i think it involves scripting with combination of HTML.

Thanks,

- Dinya.

former_member402770
Participant
0 Kudos

Hi Ingo,Anuraag,Fazith and All,

   Any Pointers to display words under each Product based on selected product.

   For some reasons i struck up with in above posts on the scripting part on the loop.

Thanks,

- Dinya.

.

IngoH
Advisor
Advisor
0 Kudos

Hello Dino,

as outlined before, you would have to load all the members from all three characteristics, load them into arrays and then "mix" them all together after that.

Ingo

former_member402770
Participant
0 Kudos

Hi Ingo,

  Iam there here on Apply Product Dimension Filter:

var arr_products = DS_1.getMembers("PRODUCTS", 30);

    arr_products.forEach(function(element2, index) {

     var arr_words1=DS_1.getMembers("Words1", 30);

      arr_words1.forEach(function(element1, index)

      {

 

        DS_1.setFilter("Words2", element1.internalKey);

        var arr_words2=DS_1.getMembers("Words2", 30);

         arr_words2.forEach(function(element, index)

       {

         LISTBOX_1.addItem( element2.text);

         LISTBOX_1.addItem( element1.text+element.text);

       });


});

});

Tried above code the loop is running without showing output instead what was expected. Is the element and index should be given unique?

Appreciate your help.


Thanks,

- Dinya.

IngoH
Advisor
Advisor
0 Kudos

Hello Dinya,

first of all I would not have the getMembers inside of the loop - which is what you have right now.

and I would also make sure that your setFilter is working at least.

if you don't see the desired output then use things like textboxes to display the values from each of the different loops to see where the code goes wrong right now.

regards

Ingo Hilgefort

former_member402770
Participant
0 Kudos

Hi Ingo,

Tried the below code based on your suggestion:

var arr_products = DS_1.getMembers("PRODUCTS", 30);

var arr_words1 = DS_1.getMembers("Words1", 30);

var arr_words2 = DS_1.getMembers("Words2", 30);

    arr_products.forEach(function(element2, index) {

     arr_words1.forEach(function(element1, index)

      {

 

        DS_1.setFilter("Words2", element1.internalKey);

      

       arr_words2.forEach(function(element, index)

       {

         LISTBOX_1.addItem( element2.text);

         LISTBOX_1.addItem( element1.text+element.text);

       });


    });

   });



Iam new to code, how to make it work (preferably with code updation).

Thanks,

- Dinya.



IngoH
Advisor
Advisor
0 Kudos

Hello Dinya,

if you are new to the code then I would suggest you start looking into the product documentation and you start with your example and start with a simple step - like 1 array and 1 output - and build it up from there.

I also would highly recommend you do not open up several messages for the same questions.

This is a forum where people will try to help you, but it is not a forum where you can expect people to give you the final code and final dashboard.

regards

Ingo Hilgefort

former_member402770
Participant
0 Kudos

Hi Ingo,

  Iam actually refering to the product documentation and accordingly remodifying the script code where i need help on this code updation specifically joining two arrays of different datasources and displaying it in  Target ListBox Component not enough documentation on this

Only one Dimension Filter Named: Product  with DS_1 Datasource

Another DS_2 Datasource with Product Member List Column/Fields and other Column/Fields as Words1,Words2,Words3 etc..

// On Apply Script on DS_1 Datasource Product Dim Filter. Here the script joins two arrays of different datasources and

var vProd = DS_1.getFilterText("YPROD");

var words1=DS_2.getMembers("Words1", 60);

var words2=DS_2getMembers("Words2", 60);

var words3=DS_2.getMembers("Words3", 60);

var arrProd = vPlant.split(";");

  arrProd.forEach(function(element, index) {

   

     DS_2.setFilterExt("YPROD", vProd);

        words1.forEach(function(Words1, index) {

          DS_2.setFilter("Words1", Words1.internalKey);

              words2.forEach(function(Words2, index) {

      

                DS_2.setFilter("Words2", Words1.internalKey);

                 

                   words3.forEach(function(Words3, index)

                   {

                    LISTBOX_1.addItem("" + index, element.substring(12));  // where Product 1 and Product 2 are selected items in Product dimension Filter

                      LISTBOX_1.addItem(Words1.internalKey+Words2.internalKey+Words3.internalKey, Words1.text+Words2.text+Words3.text); // (only the Words Concatenated Columns Members for the product selected is retrieved)

              

                   });

               }); 

       });

   });

Here I need an help on displaying both the Product and under that Words Concatenated Columns Members should display in One List Box which is my output component like below format:

Product 1

   Words1Words2Words3

Product 2

   Words1Words2Words3

Appreciate your help on this.

Thanks,

- Dinya.

mike_howles4
Active Contributor
0 Kudos

Did you intend to do a nested loop there?

former_member402770
Participant
0 Kudos

Hi Michael,

Yes because there are two different datasource like i mentioned above DS_1 which is used for Dimension Filter which has fields like Product and DS_2 which too has fields like Product, Words1, Word2, Word3..

Inturn join these two datasources and display the selected products under that Words Concatenated Columns Members for the product selected is to be retrieved.

DS_1             DS_2  with columns                      

Product          Product    Words1     Words2   Words3

ListBox Output Component:

Here I need an help on displaying both the Product and under that Words Concatenated Columns Members should display in One List Box which is my output component like below format:

Product 1

   Words1Words2Words3

Product 2

   Words1Words2Words3

Tried searching the forum for joining two arrays and mix for different sources not enough documentation on this. Any help on my above code.

Thanks,

- Dinya.

Words2   Words3
IngoH
Advisor
Advisor
0 Kudos

Hello Dinya,

you already have the nested loops.

so why don't you try in your code to first of all fill the array - one after the next - and then read values from the array - for example the first value in each array and put the output into a text field ?

You asking people to provide you with final code here but it seems - at least to me - you not trying to troubleshoot the code yourself.

you have 4 list of members, so why don't you create the first array, fill the array, read the first value and put the put into a text field.

You do that for 4 separate arrays and first of all make sure that 4 separate arrays work and you see the right output.

then you worry about the combination of text fields.

regards

Ingo Hilgefort