Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Karol-K
Advisor
Advisor

If you want to use the multiselect in scorecard, this blog is for you.

The way to do

In scorecard, when selection type is "Multi", then you are allowed to chose more rows at one time (CTRL, SHIFT buttons work then). The information will be passed to the scripting, there you can use "getSelection()" method to read it out.

The implementation

Using script, the method is giving you for every dimension all selected members (in case you use CTRL only one is given, by SHIFT more than one).

The restriction

The API is giving you the dimensions INDEPENDENTLY, therefore the multi selection is basically working only when you have only one dimension in your row scope.

Why? Via the current API it is not possible to readout the dependencies between members of more than one dimension.

How you can read it out?

/assumption: only one dimension in row scope/ then the selection is toggled and can be on or off. You need one global variable on in scripting as you need to make a code which works like a semafor:

* global variable does not have a member -> selection

* global variable already has the member -> de-selection.

Script

var


colSel = SCORECARD_1DIM.getSelectedColumnId();
var sel = SCORECARD_1DIM.getSelection();
sel.forEach(function(value, key) {
  if(key == "Product" && SELECTION_Product == "") {
  SELECTION_Product = key + "|;";
  }
  value.forEach(function(element, index) {
  if(key == "Product") {
   if(SELECTION_Product.indexOf(";" + element + ";") > -1) {
    // the element is now unselected!
  SELECTION_Product =
   SELECTION_Product.substring(
    0,
  SELECTION_Product.indexOf(element + ";"))
  +
  SELECTION_Product.substring(
  SELECTION_Product.indexOf(element + ";") + (element + ";").length
  );
      } else {
        SELECTION_Product = SELECTION_Product + element + ";";
      }
    }
  });
});
TEXT_2.setText(SELECTION_Product);
asas

As you can see, there is a simple check and modification of the selection string.

I use the ";" character in the beginning to avoid that the IF check in line 12 will be positive in case there is a key which is a substring of other key.. by this, later you need to ignore the first member after split as it is empty.

How to readout the real selection?

now, having this string, you can simply split it (ignoring first member):


var list = SELECTION_Product.split(";");
var listOut = "";
list.forEach(function(element, index) {
  if(element != "") {
      listOut = listOut + " | " + element;
  }
});
TEXT_2.setText(listOut);

In the place where I create the second output (line 5) you can make your code.

Application

In the given example, you can find 2 scorecards, the first one (_1DIM) has single dimension, as in this example. The second one (_2DIM) was a try to get out the selection with 2 dimensions - this failed for today... perhaps some other day I can find a script which makes it...

Download

The app can be downloaded here

applications/SCORECARD_SELECTION_MULTI-20160222223057.zip at master · org-scn-design-studio-communit...

Does anyone need an exact selection of combinations of 2 or more dimensions? to make it work, probably the selection API needs to be changed like "getRows()" and then "getDimensionKey("A")", etc.

feel free to comment and ask

2 Comments