cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine with scripting whether a member is a leaf of a node?

ThomasK
Participant
0 Kudos

Hi!

I´m using new unified story and scripting like to get (first) selection in a table.

var selection = Table.getSelections()[0];

The result contains the id´s of the different dimensions selected. E.g. for cost center

t.S:SAP_ALL_COSTCENTER: "[t.S:SAP_ALL_COSTCENTER].[parentId].&[1234]"

Now I want to identify whether the member of this id is a node (=node of cost center hierarchy) or a leaf (=real cost center).

How could this be achieved easily?

Thanks,

Thomas

Accepted Solutions (0)

Answers (1)

Answers (1)

eeddggaarr
Contributor

Hi ThomasK,
I am working with SAP BW as source. If you are using another source this might not be the solution:

if you use your selection and retrieve the result set for it you can identify if your selection is a hierarchy node or a leaf either from its ID/naming convention or by the exclamation point in front of leafes.

 

var sel = this.getSelections()[0]["yourDimension"];
console.log(this.getDataSource().getResultSet({"yourDimension": sel, [Alias.MeasureDimension]: "yourMeasure"})[0]);

 

node: no exclamation point in front of ID and ID starts with 0HIER_NODE. You also get the parent hierarchy node:
eeddggaarr_0-1712219699361.png

leaf => exclamation point in front of ID 
eeddggaarr_1-1712219738661.png

br
edgar

 

 

ThomasK
Participant
0 Kudos

Hi edgar, many thanks for your answer. Forgot to mention that I´m using a SAC planning model. No exclamation mark in this case.

The "&" in SAC doesn´t do the same thing.

t.S:SAP_ALL_COSTCENTER: "[t.S:SAP_ALL_COSTCENTER].[parentId].&[1234]"

In case the member is part of a hierarchy I get the & character. Using flat presentation for the dimension the & is not returned.

BR Thomas

eeddggaarr
Contributor
0 Kudos
Hi ThomasK, what if you create an array with all hierarchy node IDs or names and check with your_array(indexOf(yourSelection) if your current selection is in the list i.e. an hierarchy leaf? Not an elegant way but should work until someone posts a better way. br edgar
ThomasK
Participant
0 Kudos
Hi edgar, & is unfortunatley not the solution (see edited post before). The solution to read all dimension members is currently the only way to solve it. The problem with it is, that I have to read 150.000 products and have to loop trough them. This takes a while just to only identify if the selected cell was a node or a leaf. Seems the API could be enhanced. BR Thomas