IDimAttributeHierarchies.AddHierarchy

Fore Syntax

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

Fore.NET Syntax

AddHierarchy(Dimension: Prognoz.Platform.Interop.Dimensions.IDimensionModel;
             Attribute: Prognoz.Platform.Interop.Dimensions.IDimAttribute;
             LevelKey: uinteger): Prognoz.Platform.Interop.Dimensions.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.

Fore 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.

Fore.NET Example

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;
    attrhierarchy: IDimAttributeHierarchy;
    attrhierarchy1: IDimAttributeHierarchy;
    attrhierarchies: IDimAttributeHierarchies;
    attributehierarchieslist: IDimAttributeHierarchiesList;
    count: Integer;
    id: String;
Begin
    // Get repository
    mb := Params.Metabase;
    // 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;
                System.Diagnostics.Debug.WriteLine
                ("Number of alternative hierarchies in the list  = " + count.ToString()) Else
                    System.Diagnostics.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;
                System.Diagnostics.Debug.WriteLine("Hierarchy identifier = " + id) Else
                    System.Diagnostics.Debug.WriteLine
                        ("Alternative hierarchy is not found by selected parameters = ")
                            End If;
    // Save changes
    (dimension As IMetabaseObject).Save();
End Sub;

See also:

IDimAttributeHierarchies