Skip to Content
avatar image
Former Member

GetMembers function does not respect sorting

Hi,

I have a small script the selects 5 members and assign each of their texts to a text component. I have then made a sorting in the DS, in order to get the Top 5 based on a key figure.

My issue is that when I use the below code, I get the top 5 from the dimension sorted alphabetically, not as I sorted it in the DS.

     var arr_group=DS_TOP_5.getMembers("0COMP_CODE__ZCOMPCOTE",5);

I've tried googling and going searching here on SCN without finding the solution.

Can someone help out here?

/Kris

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 18, 2015 at 04:03 PM

    So, then I have the million dollar question...

    How to I get the first 5 dimension values into my array?

    regards,

    Kris

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 18, 2015 at 01:46 PM

    Hi Kris,

    When you display the preview of data source DS_TOP_5 in the Initial View Editor, do the Company Code members appear in the top 5 sort order you are expecting?  Can you provide a screenshot of the Initial View window?

    Regards,

    Mustafa.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Karol Kalisz

      Hi Karel,

      It does sort as desired if i use sortByMeasure(), but the question now if how to get the top 5 dimension values from the DS, as the getMembers() is not the solution.

      /Kris

  • avatar image
    Former Member
    Feb 18, 2015 at 04:35 PM
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 24, 2015 at 10:04 AM

    Hei Mustafa,

    thanks for the advice. But our customer restricts us to use SDK Extensions to avoid dependency to the SDK developer. In this case this SDK even is not supported by SAP. So for all who are in the same situation can use my template.

    I had to correct some things in the coding, but now it works fine. Please ignore my posting before and use this coding as template:

    var l_a_kpi_id = DS_META_QUERY_KPI.getMembers("M3MDSMT01", 0);
    
    // Umwandlung von Member Array in formatierten String
    var l_kpi_id_string = "";
    l_a_kpi_id.forEach(function(element, index) {
    if (element.externalKey != "#") {
    // Lokale String Variable für die Sortierung zusammensetzen
    l_kpi_id_string = l_kpi_id_string +
    element.externalKey + "/" + element.getAttributeMember("M3MDSMT20").externalKey + ";";
    }
    });
    
    // Bereinigung des letzten Semikolons
    l_kpi_id_string = l_kpi_id_string.substring(0,l_kpi_id_string.length-1);
    
    // Initialisierung der Sortierung
    var l_a_outer = l_kpi_id_string.split(";");
    var l_a_inner = l_a_outer;
    var l_kpi_id_sorted = "";
    var l_act_minimum = -1;
    
    // Sortierlogik
    l_a_outer.forEach(function(element_outer, index_outer) {
    var l_search_minimum = 1000; // Sortierindex kann maximal dreistellig sein
    var l_act_kpi_id = "";
    
    l_a_inner.forEach(function(element_inner, index_inner) {
    var l_a_act_kpi = element_inner.split("/"); // Schlüssel und Sortierindex splitten und in Array auflösen
    var l_act_kpi_sort_index = Convert.stringToInt(l_a_act_kpi[1]);
    
    // Das aktuelle Minimum in Abhängigkeit zum bereits gefundenen suchen
    if (l_act_kpi_sort_index > l_act_minimum) {
    if (l_act_kpi_sort_index < l_search_minimum) {
    l_act_kpi_id = l_a_act_kpi[0] + "/" + index_inner;
    l_search_minimum = l_act_kpi_sort_index;
    // Handling falls der Indexwert mehrfach vergeben wird
    } else if (l_act_kpi_sort_index == l_search_minimum) {
    l_act_kpi_id = l_act_kpi_id + ";" + l_a_act_kpi[0] + "/" + index_inner;
    }
    }
    });
    // Das aktuelle Minimum aktualisieren
    l_act_minimum = l_search_minimum;
    // Nur falls was gefunden wurde, das Ergebnis aktualisieren
    if (l_act_kpi_id != "") {
    l_kpi_id_sorted = l_kpi_id_sorted + l_act_kpi_id + ";";
    }
    });
    
    // Bereinigung des letzten Semikolons
    l_kpi_id_sorted = l_kpi_id_sorted.substring(0,l_kpi_id_sorted.length - 1);
    

    Regards

    Helder Matias

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks for the update Helder!

      I will definitely use this in the future, as we are also not allowed to use SDK in our dashboards.

      /Kris

  • avatar image
    Former Member
    Feb 18, 2015 at 01:23 PM

    Hi Kris,

    Have you tried using the script DS_1.sortByMeasure(measure, isSortAscending); ??

    Regards,

    Kriti

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Kriti,

      Yes, I've tried adding this right before the above mentioned code. Unfortunately this did not change the output of the getMembers function.

      /Kris

  • Feb 18, 2015 at 03:32 PM

    Hi,

    the getMembers is asking for the MasterData and you receive the list from the master data or from the InfoProvider or from the Navigation - but it would be at max sorted by the Key or sorted by the text but it will be sorted based on the member list as you are receiving master data.

    regards

    Ingo Hilgefort, Visual BI

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 24, 2015 at 08:21 AM

    Hello Kris,

    I have a similar requirement at a customer, and I have implemented a workaround for that.

    We have added a numeric attribute to our InfoObject in BW, which is responsible for the sort order - so now we have the flexibility to change this attribute and the sorting will affect Design Studio automatically. Maybe you could use this template and adapt to your specific requirement.

    var l_a_kpi_id = DS_META_QUERY_KPI.getMembers("M3MDSMT01", 0);
    // Sortierlogik
    // Umwandlung von Member Array in formatierten String
    var l_kpi_id_string = "";
    l_a_kpi_id.forEach(function(element, index) {
    if (element.externalKey != "#") {
    l_kpi_id_string = l_kpi_id_string + element.externalKey + "/" + element.getAttributeMember("M3MDSMT20").externalKey + ";";
    }
    });
    
    // Bereinigung des letzten Semikolons
    l_kpi_id_string = l_kpi_id_string.substring(0,l_kpi_id_string.length-1);
    
    var l_a_outer = l_kpi_id_string.split(";");
    var l_a_inner = l_a_outer;
    var l_kpi_id_sorted = "";
    var l_act_minimum_sort_index = 0;
    var l_act_minimum = -1; // Sortierindex kann maximal dreistellig sein
    
    l_a_outer.forEach(function(element_outer, index_outer) {
    var l_search_minimum = 1000;
    var l_act_kpi_id = "";
    
    l_a_inner.forEach(function(element_inner, index_inner) {
    var l_a_act_kpi = element_inner.split("/");
    var l_act_kpi_sort_index = Convert.stringToInt(l_a_act_kpi[1]);
    
    if (l_act_kpi_sort_index > l_act_minimum_sort_index) {
    if (l_act_kpi_sort_index < l_search_minimum) {
    l_act_kpi_id = l_a_act_kpi[0];
    l_act_minimum_sort_index = Convert.stringToInt(l_a_act_kpi[1]);
    l_search_minimum = l_act_kpi_sort_index;
    } else if (l_act_kpi_sort_index == l_search_minimum) {
    l_act_kpi_id = l_act_kpi_id + ";" + l_a_act_kpi[0];
    }
    }
    });
    l_act_minimum = l_act_minimum_sort_index;
    if (l_act_kpi_id != "") {
    l_kpi_id_sorted = l_kpi_id_sorted + l_act_kpi_id + ";";
    }
    });
    
    l_kpi_id_sorted = l_kpi_id_sorted.substring(0,l_kpi_id_sorted.length - 1);
    
    

    Regards,

    Helder Matias

    Add comment
    10|10000 characters needed characters exceeded