SCN Community Package: Hierarchy Members Accessors & Iterator
Disclaimer:
This component uses hierarchies from BW. It could be adapted to connect to Hana or a Universe, but these hierarchies have not been tested.
The component has been tested, but you may encounter some bugs. For either bugs or enhancement request, do not hesitate to post an “issue” on our GitHub.
Introduction
Hi, I am Franck BLAIS, Sap BW Consultant and Design Studio developper. I already posted 2 blog entries on my component “Hierarchical Menu” in the SDK Community package initiative.
The first one was “Multi level Dropdown Menu” and the second “Hierarchical menu for BW v2”.
I want to share a new aspect on the menu, a utility one.
In Design studio, as far of the 1.6, you can access members of a dimension, but the hierarchy members. I juste improved the “Hierarchical Menu v 1.0” with this functionality.
Rendering the hierarchical menu is not necessary and it can be used in a Utility version.
An demo application can be found here. You just need to import it. Note it’s for DS 1.6 and the datasource are CSV.
Component overview and explanations
The hierarchical menu look like this, with the embedded CSS:
You can avoid to display it by using the method “hideMenu(boolean hide)”, or changing its value directly in DS.
With the iterator, you can really easily create a navigation menu using the Tree 2.0 (or any other component, like dropdown, listbox …):
When you have assigned a Datasource and selected a dimension with a hierarchy, you can now use 3 new methods detailed below.
Loop on the members with getHierarchyMembers()
This method returns an array of Hierarchy Member that you can iterate using forEach.
Each member has for attributes (case-sensitive):
Attribute | Description |
---|---|
ID |
an integer internal ID generated while exporting it. It is corresponding to the index of each node/leaf. (The fist node will be 0, second 1 …) |
key |
hierarchy node key in BW format. It can be used as parameter for setFilter of setVariable on a characteristic with a hierarchy assigned. Example: HIERARCHY_NODE/0HIER_NODE/EUROPE |
text |
Contains the text of the node/leaf, but not only. You see, it depends on the characteristic display mode. In contrary of the key, which is the NodeKey (HIERARCHY_NODE/0HIER_NODE/EUROPE), this node would have:
If you choose to display both (Key+Text) in BEX, then the attribute text will have the concatenation of both like: “EUROPE|Europe”. Only Text will give only “Europe” while Text+Key “Europe|EUROPE”. if you need to access one of the other, you can always use “Convert.split” or the substring extractor. Or best bet: display the hierarchy as “Text” only 🙂 |
Level | Depth of the node, starts at 0. |
parentID |
ID of the parent node, -1 if no parents. You can directly access the parent form the table by using this ID as index:
|
parentKey | parentKey in BW hierarchy format. Can be used in setFilter, setVariable or setDataSelection. |
isLeaf | Boolean, tells you if you on a node or a leaf basically, meaning you cannot go further in this branch. |
nodeState | Indicated wherever the node is collapsed (COLLAPSED) or expanded (EXPANDED) in the datasource. For a leaf, nodeState = leaf. |
type | Type of the node, exactly the same as BW, either: HIERARCHY_NODE or t)he technical name of the characteristic (0MATERIAL for example) |
2 other methods are available, maybe less useful:
getHierarchyMembersSource() |
return the DS table as a string, could be useful to debug the component … |
getHierarchyMembersAsJsonString() |
Return the same table, but as a JSON String. It could be used in conjonction with the Collection component, maybe to alter the structure, values and still be able to loop and access the hierarchy members. |
I can now only hope you’ll like, and of course, use it !
Let me know if you found any bug, or need support.
Hi Frank,
Thank you for your post.
Have you any experience with getting a node state from DataSource?
I mean that every node in DataSource has a state ( EXPANDED / COLLAPSED )
I want to get data about state someway likes this (DS_2 is datasource)
var cell = DS_2.getDataAsString( "DAJKZVLWDW4O3PDK5CMQ0E044", {"ZTRMANUF":"HIERARCHY_NODE/ZTRMANUF/PR0206"});
Scorecard (standard component) has availability for showing node state.
There is a ".../nodeState" expression for it. Regarding settings for scoretab i need to use "/nodeState" somehow. Do you have any experiense in using "getDataAsString" for getting directly node state?
Rgds,
Kirill
Hi Kirill,
I don't have any experience with the scorecard unfortunately.
This addition to the Hierarchy menu has been designed especially to loop on the hierarchy members, and for instance getting the node state.
You could invoke .getHierarchyMembers(), loop on it to locate the node you're looking for and read the property nodeState. So the getDatastring would give you the measure value and the members reading with the extension the node state.
Hope it helps.
Hi Frank,
Is there any chance, can we able to build Hierarchy in Design Studio itself, which is not there in BW Query, if so can you please gimme some example on that...
Hello Pamarthi,
You could build a hierarchy and put it in a Tree View, for instance, but the Crosstab will never support it.
The Hierarchy member iterator has been designed for standard BW hierarchy.
I don't think you will be able to generate a real BW hierarchy like that. Maybe try to generate one in BW itself ? I think there is an option to have dynamic hiers (have a look on the info object itself).
Sorry, I can't help more than that.