cancel
Showing results for 
Search instead for 
Did you mean: 

How to check if a value is in the list.

0 Kudos

I have buttons for 'Products' on the dashboard.  I have two different datasources DS_1 which gets list of 'CITY' and 'Products'.  DS_2 gets data of 'Products' and related Sales.  When I select any 'Product' button, I pass the parameter to DS_2 and load the datasource and get sales data only for one particular product to display in chart which is set to visible on selection of the button.  However not always do all products have data in the database for a particular City, and sometimes, when I click a product button it passes the parameter to the datasource DS_2 and since there is no value of that particular Product sales in the database, dashboard is displaying prompt window to enter a new "Product' value.

I can get a default list of products from database; and If I can compare it to DS_1 data and check if a particular City has sales for these products I can keep the button active else I want to make the button inactive so the user knows that the button cannot be clicked since there is no data available for the selected city for a particular product.

I am thinking if I get the list of products for a city1 say ('a', 'b', 'c') and compare it with all products ('a', 'b', 'c', 'd', 'e') I will know that there is no data for product 'd' and 'e'.  I would like to identify these two products and put in some method to leave the buttons inactive or display a message on the dashboard.

Please let me know if there is a way out using javascript difference between arrays or something.

Thanks a ton in advance.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Vijay,

You could use the indexOf function.

Get the list of all the products from DS_2, and store it in a string array variable, say str1.

Now, when the product from the first datasource DS_1 is selected, use the indexOf function to check if it appears in the variable str1.

Let's say the products of DS_1 are displayed in a crosstab called CROSSTAB_1, and the user clicks on a particular product. If the product is also in DS_2, only then will a button be enabled.

Then your the required script would be similar to this:

if(str1.indexOf(CROSSTAB_1.getSelectedMember("ZPRODUCT").text)>0)

{

  BUTTON_1.setEnabled(true);

}

else

{

  BUTTON_1.setEnabled(false);

}

0 Kudos

Hi Anurag,

Thanks for your response.

I do not want the value to be selected before I disable the buttons.  I want the buittons for which there is no data on load of the dashboard.  After your response, I made some changes.  I am hardcoding the text of the buttons which are of known products.  Product_1 to Product_7.  I am loading DS_1 which will filter data on load of dashboard for a particular city.

I will have buttons for each product when the dashboard loads for a particular city, I have the button texts named as PRODUCT_1, PRODUCT_2 etc, only the products available for the city are available in DS_1.  I wanted to check whether each of these texts is available in the DS_1 data.  I am using the below based on your suggestion.

//create a variable str1

str1=[DS_1.getMemberList("ZPRODUCT", MemberPresentation.TEXT, MemberDisplay.TEXT, 0)];

//Next I provided the below query:

if(str1.indexOf("PRODUCT_1")>0)

{

  product_1_BUTTON.setEnabled(true);

}

else

{

  product_1_BUTTON.setEnabled(false);

}

In edit initial view of DS_1 I can clearly see PRODUCT_1 as one of the member list texts, but still this does not work.

The button is still disabled.

When I tried to get the index of the text that I am sure should  be there I get '-1', which means it is not found. 

TEXT_1.setText(str1.indexOf("PRODUCT_1")+"");

However; even if I get a product name that is not available PRODUCT_Z still the button is not enabled.  which is correct but I don't think this  is happening because  of the script.

What could be the reason.  Response much appreciated. Thanks again.

Regards,

VB

Karol-K
Advisor
Advisor
0 Kudos

Hi Vijay,

can you use the collection SDK component or you need a solution in standard design studio?

based on that I need some time to find the solution.

Karol

Karol-K
Advisor
Advisor
0 Kudos

Hello Vinay,

short answer:

first, you are asking in the script for a member list, this cannot be used for the "indexOf" check.. this is why this is not working. The example of Anuurag is applying on a single member - you can see if the selected member is yours.

I think, this what you want is to get all members from result set and check if one is exisitng or not, correct?

here such script:

// read all members (max 999)

var members = DS_1.getMembers("0BC_COUN", 999);

// initialize some variable

var memberIsIncluded = false;

// loop and check if one of the members

members.forEach(function(element, index) {

  var memberKey = element.internalKey;

 

  if(memberKey == "my key") {

  // found...

  memberIsIncluded = true;

  }

});

if(memberIsIncluded) {

// your code.

}

Karol

0 Kudos

Karol Kalisz,

Thanks a lot for your time.  I have buttons which represent each member of a KPI such as SALES, INVENTORY etc.  Now my data base has data i.e. dollars of sales or Inventory dollars for each country/region.  I set another datasource which has as key column which is a concatenated column of country name and kpi (sales/inventory etc).  I set Sales button active on load which means 'on start up' my variable will pick uf the country from the drop down and concatenate it with the button text 'SALES' i.e. the variable value will now be USSALES.  USSALES will be a keycolumn value which I am passing as prompt using

DS_KPI.LoadDatasource();

APPLICATION.setvariablevalue("psEnter keyvalue", v_variable);

meaning, the DS_KPI datasource will be filtered using the prompt value of v_variable (in this case it is USSALES).  Then it gets a single row from the database which I am displaying on the dashboard.

Second part of the story.  There is another button INVENTORY and the v_button=="INVENTORY" when I select the button.  Then based on this value and the country dropdown value the v_variable should become USINVENTORY.  However assuming there is no data for Inventory in the database when I pass prompt value, I get a popup on my dashboard asking me to enter a correct prompt.  I want the dashboard to identify while loading sales data on load that there is no data for USINVENTORY in database and disable the button INVENTORY on load of the dashboard.

The third part of the story: assume there is no data for Sales itself.  And I have set Sales button to enabled on load it means as soon as I load the dashboard it will pick the country US and button text (default SALES) and since there is no data in databse for USSALES I get a prompt popup.  I want the dashboard to display an error message saying there is no data for Sales, please select another KPI.  Then the user selects Inventory button and the chart is displayed.

I don't want to use SDK.  I think I figured something and I am working on it.  I will  update you if I am able to find a simple solution.  Please see if you can come up with something by then.

I appreciate your interest and all the others who responded to my question, in solving my problem.  Thanks all of you.  I will  update if I find a workaround.

Regards,

VB

kohesco
Active Contributor
0 Kudos

Hi,

By default when a value from DS_1 does not mach with DS_2, he will show all data from DS_2.

I used script = if filter is empty set chart on hide, maybe you can set your button on hide ?

Grtz

Koen