on ‎2024 Aug 30 10:29 AM
Hello Team,
How do I populate a dropdown list with hierarchy values?
Example :
Dimension: "Centre"
Structure might be:
lvl1: Region
lvl2: - North
lvl3: - North East
lvl2: - South
lvl3: - South West
My requirement is to add all the levels of Hierarchy into single Dropdown. Below I have attached screenshot for dropdown expected output.
Thanks & Regards
Mohammed
Request clarification before answering.
Hi there , as the previous comment - dropdowns will only show a flat list of dimension members.
You could fake it using a table with linked analysis to perform the filtering.
In this example below I used code in the green arrow image to expand/contract a panel which contains the table.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello- unfortunately I'm not sure you can populate a single dropdown exactly as you wish. You can populate all members from a dimension in a single dropdown, but it will not be indented as per your screenshot, it will just be a flat list:
// "Model" has to be added as a planning model in the scripting section (add planning model, then choose your model)
var members = Model.getMembers("DIMENSION",{limit:3000}); // This gets the list of members from your dimension
var list_array = ArrayUtils.create(Type.string);
for(var i=0;i<members.length;i++) {
list_array.push(members[i].id);
}
console.log(dropdown_list);
// The above will take all of the members in the dimension, and populate an array with the IDs. This is then written to the console to check you are happy.
You can then add some code to populate your dropdown like below:
for (var j=0;j<list_array.length;j++) {
Dropdown_1.addItem(list_array[j]);
}
I'm not great at the coding so there are probably better ways to write this, but this approach works. However, this will just bring the full list of dimension members into your dropdown, without the indentations/hierarchy view.
One suggestion could be to have several dropdowns which cascade into each other.
For example, the first dropdown is the first level of the hierarchy, then second dropdown populates based on selection from the first (based on code "onSelect" of Dropdown for Level 1), and so on.
E.g.
Within the "For" loop above, you can replace with a condition to check a property (imagine this is a level of the hierarchy):
if(list_array[i].properties["Level"]==="1") {
list_level_1.push(members[i].id);
}
and continue for multiple levels. Each level can populate its own dropdown. The first bit of code getting the members of the dimension can be added to the "oninitialisation" of the story, and the cascading dropdowns can be populated using "onSelect" of the dropdowns.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To be honest , a dropdown can be populated using any underlying model as the source.
The code below is the bare bones to populate a dropdown list.
Model: Best Run Juice
Dimension: Location_4nm2e04531 (Location)
Table Name: Table_1
Dropdown: ddl_location
Script:
var location=Table_1.getDataSource().getMembers("Location_4nm2e04531");
for (var l=0;l<location.length;l++)
{ddl_location.addItem(location[l].id,location[l].description);}
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.