Count: Integer;
Count: uinteger;
The Count property returns number of alternative hierarchies in the list.
To get alternative hierarchy, use IDimAttributeHierarchiesList.Item.
Executing the example requires that repository contains table dictionary with the DIM_SEP identifier containing two levels of hierarchies.
Add links to the Dimensions, Metabase system assemblies.
Sub UserProc;
Var
mb: IMetabase;
dimension: IDimensionModel;
attribute: IDimAttribute;
attributes: IDimAttributes;
hierarchies: IDimAttributeHierarchiesList;
count: Integer;
attrhierarchy1: IDimAttributeHierarchy;
attrhierarchy2: IDimAttributeHierarchy;
attrhierarchy3: IDimAttributeHierarchy;
attrhierarchy4: IDimAttributeHierarchy;
attrhierarchies: IDimAttributeHierarchies;
id, name, name1: string;
key: integer;
Begin
// Get repository
mb := MetabaseClass.Active;
// Get dictionary
dimension := mb.ItemById("DIM_SEP").Edit As IDimensionModel;
// Get dictionary attributes
attributes := dimension.Attributes;
// Get the Name attribute
attribute := attributes.FindById("NAME");
// Get attribute hierarchies
hierarchies := attribute.Hierarchies;
// Get collection of dictionary hierarchies
attrhierarchies := dimension.AttributeHierarchies;
// Get number of hierarchies
count := hierarchies.Count;
// Display to the console number of attribute hierarchies
Debug.WriteLine("Number of hierarchies = " + count.ToString);
// Get the first hierarchy
attrhierarchy1 := hierarchies.Item(0);
//Display to the console identifier of the first hierarchy
id := attrhierarchy1.Id;
Debug.WriteLine("Identifier of the first hierarchy = " + id);
// Find hierarchy by identifier
attrhierarchy2 := hierarchies.FindById("ATTR_HIER_SOURCE10");
If attrhierarchy2 <> Null Then
// Display to the console hierarchy key
key := attrhierarchy2.Key;
Debug.WriteLine("Hierarchy key = " + key.ToString) Else
Debug.WriteLine("Hierarchy with this identifier is not found")
End If;
// Find hierarchy by key
attrhierarchy3 := hierarchies.FindByKey(3);
If attrhierarchy3 <> Null Then
// Display to the console name of the attribute containing hierarchy
name := attrhierarchy3.Name;
Debug.WriteLine("Name of the attribute containing hierarchy = " + name) Else
Debug.WriteLine("Hierarchy with this key is not found")
End If;
// Find hierarchy at the second level
attrhierarchy4 := hierarchies.FindByLevel(2);
If attrhierarchy4 <> Null Then
// Display to the console name of the attribute containing hierarchy
name1 := attrhierarchy4.Name;
Debug.WriteLine("Name of the attribute containing hierarchy = " + name1) Else
Debug.WriteLine("Hierarchy is not found at this level")
End If;
End Sub UserProc;
After executing the example the console displays the following information:
Number of alternative hierarchies.
Identifier of the first hierarchy in the list.
Key of the hierarchy found by key.
Name of the attribute containing hierarchy found by key.
Name of the attribute containing hierarchy found at the second level.
The requirements and result of the Fore.NET example execution match with those in the Fore Example.
Imports Prognoz.Platform.Interop.Dimensions;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
dimension: IDimensionModel;
attribute: IDimAttribute;
attributes: IDimAttributes;
hierarchies: IDimAttributeHierarchiesList;
count: Integer;
attrhierarchy1: IDimAttributeHierarchy;
attrhierarchy2: IDimAttributeHierarchy;
attrhierarchy3: IDimAttributeHierarchy;
attrhierarchy4: IDimAttributeHierarchy;
attrhierarchies: IDimAttributeHierarchies;
id, name, name1: string;
key: uinteger;
Begin
// Get repository
mb := Params.Metabase;
// Get dictionary
dimension := mb.ItemById["DIM_SEP"].Edit() As IDimensionModel;
// Get dictionary attributes
attributes := dimension.Attributes;
// Get the Name attribute
attribute := attributes.FindById("NAME");
// Get attribute hierarchies
hierarchies := attribute.Hierarchies;
// Get collection of dictionary hierarchies
attrhierarchies := dimension.AttributeHierarchies;
// Get number of hierarchies
count := hierarchies.Count;
// Display to the console number of attribute hierarchies
System.Diagnostics.Debug.WriteLine("Hierarchies number = " + count.ToString());
// Get the first hierarchy
attrhierarchy1 := hierarchies.Item[0];
//Display to the console identifier of the first hierarchy
id := attrhierarchy1.Id;
System.Diagnostics.Debug.WriteLine("Identifier of the first hierarchy = " + id);
// Find hierarchy by identifier
attrhierarchy2 := hierarchies.FindById("ATTR_HIER_SOURCE10");
If attrhierarchy2 <> Null Then
// Display to the console hierarchy key
key := attrhierarchy2.Key;
System.Diagnostics.Debug.WriteLine
("Hierarchy key = " + key.ToString()) Else
System.Diagnostics.Debug.WriteLine
("Hierarchy with this key is not found")
End If;
// Find hierarchy by key
attrhierarchy3 := hierarchies.FindByKey(3);
If attrhierarchy3 <> Null Then
// Display to the console name of the attribute containing hierarchy
name := attrhierarchy3.Name;
System.Diagnostics.Debug.WriteLine
("Name of the attribute containing hierarchy = " + name) Else
System.Diagnostics.Debug.WriteLine
("Hierarchy with this key is not found")
End If;
// Find hierarchy at the second level
attrhierarchy4 := hierarchies.FindByLevel(2);
If attrhierarchy4 <> Null Then
// Display to the console name of the attribute containing hierarchy
name1 := attrhierarchy4.Name;
System.Diagnostics.Debug.WriteLine
("Name of the attribute containing hierarchy = " + name1) Else
System.Diagnostics.Debug.WriteLine
("Hierarchy is not found at this level")
End If;
End Sub;
See also: