Links: ICalcBlockIteratorStubDimensionLinks;
The Links property returns the collection of links between data source dimension and data consumer dimension.
Executing the example requires that the repository contains a calculation algorithm with the ALGORITHM identifier containing a calculation block. A data consumer and data sourcesshould be created for calculation block, they contain at least two dimensions.
Add links to the Algo, Cubes, Dimensions, Metabase system assemblies. Add links to the assemblies required for working with calculation algorithms.
Sub UserProc;
Var
MB: IMetabase;
MObj: IMetabaseObjectDescriptor;
Algo: ICalcObject;
List: ICalcObjectsList;
CalcAlgo: ICalcAlgorithm;
CalcBlock: ICalcObject;
Block: ICalcBlock;
IteratorModel: ICalcBlockIteratorModel;
IteratorStub: ICalcBlockIteratorStub;
IteratorStubs: ICalcBlockIteratorStubs;
IteratorStubDimension: ICalcBlockIteratorStubDimension;
IteratorStubDimensions: ICalcBlockIteratorStubDimensions;
DimensionModel: IDimensionModel;
StubOut: IVariableStub;
StubDim: IDimensionModel;
Attr, StubOutAttr: IDimAttributes;
AddLink: ICalcBlockIteratorStubDimensionLink;
Links: ICalcBlockIteratorStubDimensionLinks;
Begin
// Get calculation algorithm
MB := MetabaseClass.Active;
MObj := MB.ItemById("ALGORITHM");
Algo := CalcObjectFactory.CreateCalcObject(MObj, True);
CalcAlgo := Algo As ICalcAlgorithm;
// Get list of calculation algorithm objects
List := CalcAlgo.Items;
// Get calculation block
CalcBlock := List.Item(0);
Block := CalcBlock As ICalcBlock;
// Set up links between data source dimensions and data consumer dimensions
IteratorModel := Block.EditIteratorModel;
// Get data sources collection
IteratorStubs := IteratorModel.Stubs;
// Get the first data source
IteratorStub := IteratorStubs.Item(0);
// Display name of obtained data source in the console
Debug.WriteLine("Data source name: " + IteratorStub.Stub.Name);
// Get collection of data source dimensions
IteratorStubDimensions := IteratorStub.Dimensions;
// Get the second dimension of data source, for which a link will be created
IteratorStubDimension := IteratorStubDimensions.Item(1);
// Get data consumer
StubOut := Block.StubOut;
// Get the second dimension of data consumer, for which a link will be created
DimensionModel := StubOut.Dimension(1);
// Add a new link
Links := IteratorStubDimension.Links;
AddLink := Links.Add;
// Set data source for link
AddLink.Stub := IteratorStubDimension.Stub;
// Get data source dimension structure
StubDim := IteratorStubDimension.Dimension;
// Set data source dimension structure
AddLink.Dimension := StubDim;
// Get data source dimension attributes
Attr := StubDim.Attributes;
// Set the first attribute of data source dimension (key)
AddLink.DestinationAttribute := Attr.Item(0);
// Set data consumer dimension to be linked
AddLink.Owner := DimensionModel;
// Get data consumer dimension attributes
StubOutAttr := DimensionModel.Attributes;
// Set the first attribute of data consumer dimension (key)
AddLink.SourceAttribute := StubOutAttr.Item(0);
// Check if all required link parameters are set
// If there are changes, check link
If AddLink.IsDirty = True Then
// Check if all mandatory fields are filled in
If AddLink.IsFullLink = False Then
// Unlink if not all mandatory fields are filled in
IteratorStub.CleanNotFullLink;
End If;
// To apply changes, save the model
IteratorModel.Save;
IteratorModel.Dispose_;
End If;
Block.SaveObject;
End Sub UserProc;
After executing the example the link between the second dimension of the first data source dimension and data consumer dimension is set by the Key attribute. The console displays name of the data source, in which the link is set up. If not all mandatory fields are not filled in during the setup, the link will be undone.
See also: