cancel
Showing results for 
Search instead for 
Did you mean: 

Get dimension values with getMembers?

Former Member
0 Kudos

Hi,

I have a data source with the following dimensions in my SAP Design Studio dashboard:

Key 1 (String)

Key 2 (String)

Measure 1 (int)

KEY_1

Description 1

x

KEY_2

Description 2

y

KEY_3

Description 3

z

KEY_4

Description 4

w

I would really like to display the different keys in text fields because I am going to display the descriptions. After a heavy amount of searching online, I have come to an understanding that getting dimension values is quite difficult. (I am not trying to get the measure which easily can be obtained with the DS_1.getData() method)

A work around I have found is to use the following code:

var Dim_For_Description= DS_1.getMembers(Dimension, 100); 

Dim_For_Description.forEach(function(Dim_Desc, Dim_i) { 

if(Dim_i==1){Desc_1= Dim_Desc.internalKey;}

else if(Dim_i==2){Desc_2= Dim_Desc.internalKey;}

else if(Dim_i==3){Desc_3= Dim_Desc.internalKey;}

else if(Dim_i==4){Desc_4= Dim_Desc.internalKey;}

else if(Dim_i==5){Desc_5= Dim_Desc.internalKey;}

else if(Dim_i==6){Desc_6= Dim_Desc.internalKey;}

else if(Dim_i==7){Desc_7= Dim_Desc.internalKey;}

else if(Dim_i==8){Desc_8= Dim_Desc.internalKey;}

else if(Dim_i==9){Desc_9= Dim_Desc.internalKey;}

else if(Dim_i==10){Desc_10= Dim_Desc.internalKey;}

});

The problem is that the DS_1.getMembers() sorts the members alphabetically while I need them to be according to the sorting in the DS.

Is there any work-sround for this problem?

I am using Design Studio 4.1


Thank you.

Accepted Solutions (0)

Answers (1)

Answers (1)

MustafaBensan
Active Contributor
0 Kudos

Hi Martha,

It is a known limitation of the getMembers() function that the sort order is based on the master data and not the data source.  I don't believe there is a workaround to get the data source order.

Can I ask why you don't just display the data in a Crosstab component?

Regards,

Mustafa.

Former Member
0 Kudos

Hi Mustafa,

The reason i cannot use a crosstab is because I need the values into variables for a global script. The values will for instance decide which CSS class I am going to apply to certain components etc etc.

In addition to this, I am going to display certain values in text fields in different places on the dashboard, so a crosstab will not cover these requirements.

Regards,

Martha

MustafaBensan
Active Contributor
0 Kudos

Hi Martha,

Thanks for the clarification.  What is the basis for sort order of the key dimension in your scenario?

Mustafa.

Former Member
0 Kudos

Hi Mustafa,

The Key 2 is sorted according to Key 1. This means that for each Key 1 (sorted in ascending order), there should be one description (Key2). Key 1 is sorted alphabetically, which it is supposed to be, but Key 2 is not meant to be alphabetically.

If there had been a method which allowed me to get the dimension value, that would have been perfect.

DS_1.getData(Key 2, {Key 1="Key_01"})

Sadly, Design Studio does not support that for some reason, and I am left to find another way to obtain my dimension values.

Thank you for trying to help me.

Martha.

MustafaBensan
Active Contributor
0 Kudos

Hi Martha,

Do you think you would be able to add a new sort key value as a measure to your data source?  For example having values of '1' for KEY_1, '2' for KEY_2, '3' for KEY_3 etc?  If so, I can try an idea that might get you the desired result.

Let me know,

Mustafa.

Former Member
0 Kudos

Hi Mustafa,

Yes, that might be a possibility. I am working with bex queries, so I think I might be able to add such a key value. I would be grateful if you would try your idea.

Martha

MustafaBensan
Active Contributor
0 Kudos

Okay, I'll test my idea based on that assumption and get back to you soon.

MustafaBensan
Active Contributor
0 Kudos

Hi Martha,

Okay, so the penny just dropped and I have realised that we don't even need to add a key value measure to your BEx Query.  Going by your example of a need for DS_1.getData(Key 2, {Key 1="Key_01"}), my understanding is that all you really want to be able to do is explicitly lookup the description for a particular key when needed.  This can be achieved using the Collection Utility and JSON Object components from the Design Studio SDK Development Community.

Basically, the idea is that we populate a Collection component with key/description pairs which can be accessed via a lookup. 

My test application looks like this:

The steps are as follows:

1.  Add a Collection and JSON Object component to your application as shown below:

2.  Code the "On Startup" event script of the application as follows to populate the collection:

var myMembers = DS_1.getMembers("ZOSTATE", 100);

myMembers.forEach(function(member, index) {

 

  JSONOBJECT.addProperty("ZOSTATE", member.internalKey);

  COLLECTION.addItem(member.internalKey, member.text, DS_1.getData("006EIC2OSTY2YB65GRCSC3OO2", JSONOBJECT.getAsMultiDimFilter()).value);

 

});

I have included a measure value for completeness based on your data source table example.  If you don't need this then you can do away with the JSONOBJECT component and simply code the script as follows:

COLLECTION.addItem(member.internalKey, member.text, 0.0);

3.  As an example of how to look up the description for a particular key, a button "On Click" script is coded as follows (but you can adapt as needed):

var memberInfo = COLLECTION.getEntryByKey("CO");

TEXT_1.setText(memberInfo.key + " - " + memberInfo.label + " ( " + memberInfo.value + " )");

Let me know if this addresses your requirement,

Mustafa.

Former Member
0 Kudos

Hi Mustafa,

Thank you for taking the time to find a solution. I will try it out and let you know

Martha.

MustafaBensan
Active Contributor
0 Kudos

No problems, Martha.  I hope you are able to achieve the desired result.  As an additional point, if you need to loop through the collection in a particular order, you can apply the sortByKey(), sortByLabel() or sortByValue() methods.

Regards,

Mustafa.