IDimAttributeHierarchies.AddHierarchy

Syntax

AddHierarchy(Dimension: IDimensionModel;
             Attribute: IDimAttribute;
            [LevelKey: Integer = -1]): IDimAttributeHierarchy;

Parameters

Dimension. Dictionary structure.

Attribute. Dictionary attribute.

LevelKey. Attribute hierarchy level.

Description

The AddHierarchy method adds alternative hierarchy basing on set attribute.

Comments

If the -1 value is sent to the LevelKey parameter, alternative hierarchy will be added in specified attribute, independent from the level.

Example

Executing the example requires that repository contains table dictionary with the DIM_SEP identifier Containing attribute with the NAME identifier.

Add links to the Dimensions, Metabase system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    dimension: IDimensionModel;
    attribute: IDimAttribute;
    attributes: IDimAttributes;
    attrhierarchy: IDimAttributeHierarchy;
    attrhierarchy1: IDimAttributeHierarchy;
    attrhierarchies: IDimAttributeHierarchies;
    attributehierarchieslist: IDimAttributeHierarchiesList;
    count: Integer;
    id: String;
Begin
    // Get repository
    mb := MetabaseClass.Active;
    // Get dictionary
    dimension := mb.ItemById("DIM_SEP").Edit As IDimensionModel;
    // Get collection of dictionary attributes
    attributes := dimension.Attributes;
    // Get the Name attribute
    attribute := attributes.FindById("NAME");
    // Get collection of dictionary hierarchies
    attrhierarchies := dimension.AttributeHierarchies;
    // Add new hierarchy in collection
    attrhierarchy := attrhierarchies.AddHierarchy(dimension, attribute, 1);
    // Find and display to the console number of alternative hierarchies
    // in the list by attribute key
    attributehierarchieslist := attrhierarchies.FindByAttribute(3);
        If attributehierarchieslist <> Null Then
            count := attributehierarchieslist.Count;
                Debug.WriteLine
                    ("Number of alternative hierarchies in the list  = " + count.ToString) Else
                        Debug.WriteLine("Alternative hierarchies are not found in the list")
                            End If;
    // Find and display to the console identifier of alternative hierarchy
    // found by attribute level
    attrhierarchy1 := attrhierarchies.FindByAttributeLevel(22);
        If attrhierarchy1 <> Null Then
            id := attrhierarchy1.Id;
                Debug.WriteLine("Hierarchy identifier = " + id) Else
                    Debug.WriteLine
                        ("Alternative hierarchy is not found by selected parameters = ")
                            End If;
    // Save changes
    (dimension As IMetabaseObject).Save;
End Sub UserProc;

After executing the example alternative hierarchy will be added to selected attribute, the console will display number of alternative hierarchies and identifier of alternative hierarchy.

See also:

IDimAttributeHierarchies