Alternative Hierarchies

Alternative hierarchies enable the user to create different view options for a single dictionary. The IDimHierarchies interface works with the collection of alternative hierarchies. The Hierarchies property can be used to get collection of alternative dictionary hierarchies.

Other repository dictionaries function as alternative hierarchies. Binding with the dictionary requires index in the initial dictionary. This index should be specified in the IDimHierarchies.OriginalIndex property. To create a new alternative hierarchy, dictionary structure should be passed to the IDimHierarchies.Add method. The dictionary functioning as alternative hierarchy should also contain index. After creating alternative hierarchy this index should be included into the IDimHierarchy.SourceIndex property. Using the IDimHierarchy.SourceAttribute property, it is necessary to match all the attributes of initial dictionary and dictionary functioning as alternative hierarchy.

Var
    MB: IMetabase;
    OriginDim, AlternDim: IDimensionModel;
    OriginAttrs, AlternAttrs: IDimAttributes;
    Attr: IDimAttribute;
    Hierarchies: IDimHierarchies;
    Hierarchy: IDimHierarchy;
Begin
    MB := MetabaseClass.Active;
    //Receiving structure of main dictionary
    OriginDim := MB.ItemById("Dim_1").Edit As IDimensionModel;
    //Receiving structure of the dictionary, that is used as alternative hierarchy
    AlternDim := MB.ItemById("Alternative_Dim").Bind As IDimensionModel;
    Hierarchies := OriginDim.Hierarchies;
    //Indication of index for binding to alternative hierarchies
    Hierarchies.OriginalIndex := OriginDim.Indexes.PrimaryIndex;
    //Creating new alternative hierarchy
    Hierarchy := Hierarchies.Add(AlternDim);
    //Indication of index
    Hierarchy.SourceIndex := AlternDim.Indexes.PrimaryIndex;
    //Receiving attributes of initial and alternative dictionaries for matching
    //It is supposed that the number and identifiers of attributes in dictionaries match
    OriginAttrs := OriginDim.Attributes;
    AlternAttrs := AlternDim.Attributes;
    For Each Attr In OriginAttrs Do
        Hierarchy.SourceAttribute(Attr) := AlternAttrs.FindById(Attr.Id);
    End For;
    //Saving initial dictionary
    (OriginDim As IMetabaseObject).Save;

The IDimHierarchies.DefaultHierarchy property may indicate which alternative hierarchy is used when opening the dictionary.

See also:

Additional Dictionary Objects