AdditionalHierarchy: IDimHierarchiesInstance;
AdditionalHierarchy: Prognoz.Platform.Interop.Dimensions.IDimHierarchiesInstance;
The AdditionalHierarchy property returns an object for working with an alternative hierarchy.
Alternative hierarchy is a hierarchy of any other dictionary linked to the hierarchy of the main dictionary in order to match elements or a custom hierarchy created on dimensions editing or adding a new calculated element.
Executing the example requires that the repository contains table dictionaries with the DIC_RF_AH and FACTS_AH identifiers. The DIC_RF_AH dictionary is considered as a main dictionary, and FACTS_AH is considered as an alternative hierarchy dictionary.
Add links to the Dimensions, Metabase system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
OriginalModelObj: IMetabaseObject;
OriginalModel, AlternateModel: IDimensionModel;
Hierarchies: IDimHierarchies;
Alt_Hierarchy: IDimHierarchy;
Origin_Attributes, Alt_Attributes: IDimAttributes;
Origin_Attr, Alt_Attr: IDimAttribute;
dimInstance: IDimInstance;
dimSel: IDimSelection;
i: Integer;
Begin
// Get repository
Mb := MetabaseClass.Active;
// Get table dictionary
OriginalModelObj := Mb.ItemById("DIC_RF_AH").Edit;
OriginalModel := OriginalModelObj As IDimensionModel;
// Get alternative hierarchy source
AlternateModel := Mb.ItemById("FACTS_AH").Bind As IDimensionModel;
Hierarchies := OriginalModel.Hierarchies;
// Determine index, containing keys of elements for alternative hierarchy
Hierarchies.OriginalIndex := OriginalModel.Indexes.PrimaryIndex;
// Add source alternative hierarchy
Alt_Hierarchy := Hierarchies.Add(AlternateModel);
// Determine index containing keys for comparing elements of main and alternative dictionary
Alt_Hierarchy.SourceIndex := AlternateModel.Indexes.PrimaryIndex;
Origin_Attributes := OriginalModel.Attributes;
Alt_Attributes := AlternateModel.Attributes;
// Link source dimension attributes with attributes from alternative hierarchy source by identifier
For i := 0 To Origin_Attributes.Count - 1 Do
Origin_Attr := Origin_Attributes.FindById("NAME");
Alt_Attr := Alt_Attributes.FindById("NAME");
Alt_Hierarchy.SourceAttribute(Origin_Attr) := Alt_Attr;
End For;
OriginalModelObj.Save;
// Replace main hierarchy with alternative one
dimInstance := OriginalModelObj.Open(Null) As IDimInstance;
dimSel := dimInstance.CreateSelection;
dimSel.InitAdditionalHierarchy(Alt_Hierarchy);
dimSel.Hierarchy := dimSel.AdditionalHierarchy;
// Save dictionary
OriginalModelObj.Save;
End Sub UserProc;
After executing the example an alternative hierarchy is added to the main dictionary.
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;
OriginalModelObj: IMetabaseObject;
OriginalModel, AlternateModel: IDimensionModel;
Hierarchies: IDimHierarchies;
Alt_Hierarchy: IDimHierarchy;
Origin_Attributes, Alt_Attributes: IDimAttributes;
Origin_Attr, Alt_Attr: IDimAttribute;
dimInstance: IDimInstance;
dimSel: IDimSelection;
i: Integer;
Begin
// Get repository
Mb := Params.Metabase;
// Get table dictionary
OriginalModelObj := Mb.ItemById["DIC_RF_AH"].Edit();
OriginalModel := OriginalModelObj As IDimensionModel;
// Get alternative hierarchy source
AlternateModel := Mb.ItemById["FACTS_AH"].Bind() As IDimensionModel;
Hierarchies := OriginalModel.Hierarchies;
// Determine index, containing keys of elements for alternative hierarchy
Hierarchies.OriginalIndex := OriginalModel.Indexes.PrimaryIndex;
// Add source alternative hierarchy
Alt_Hierarchy := Hierarchies.Add(AlternateModel);
// Determine index containing keys for comparing elements of main and alternative dictionary
Alt_Hierarchy.SourceIndex := AlternateModel.Indexes.PrimaryIndex;
Origin_Attributes := OriginalModel.Attributes;
Alt_Attributes := AlternateModel.Attributes;
// Link source dimension attributes with attributes from alternative hierarchy source by identifier
For i := 0 To Origin_Attributes.Count - 1 Do
Origin_Attr := Origin_Attributes.FindById("NAME");
Alt_Attr := Alt_Attributes.FindById("NAME");
Alt_Hierarchy.SourceAttribute[Origin_Attr] := Alt_Attr;
End For;
OriginalModelObj.Save();
// Replace main hierarchy with alternative one
dimInstance := OriginalModelObj.Open(Null) As IDimInstance;
dimSel := dimInstance.CreateSelection();
dimSel.InitAdditionalHierarchy(Alt_Hierarchy);
dimSel.Hierarchy := dimSel.AdditionalHierarchy;
// Save dictionary
OriginalModelObj.Save();
End Sub;
See also: