IMsTransformObjectList.FindByKey

Syntax

FindByKey(Key: Integer): IMsTransformObject;

Parameters

Key. Key of the searched object in the collection.

Description

The FindByKey method finds object in the collection by its key.

Comments

If the object with specified key is not found, the method returns Null.

Example

Executing the example requires that the repository contains a time series database with the FC identifier. A model with the MODEL_ATTR identifier must be available in the modeling container of this database. The model is calculated as determinate equation. Also, before executing the procedure it is necessary to add links to the Ms, Cubes, Rds, Metabase system assemblies.

Sub UserProc;

Var

Mb: IMetabase;

RubrDescr: IMetabaseObjectDescriptor;

Rubr: IRubricator;

MsDescr: IMetabaseObjectDescriptor;

Model: IMsModel;

Transform: IMsFormulaTransform;

TransformVarables: IMsFormulaTransformVariables;

TransVar: IMsFormulaTransformVariable;

FactsAttrs: IMetaAttributes;

Attr: IMetaAttribute;

DictDescr: IMetabaseObjectDescriptor;

ObjList: IMsTransformObjectList;

TransfObj: IMsTransformObject;

TermTrue, TermFalse: String;

Determ: IMsDeterministicTransform;

Expr: IExpression;

FormulaTerm: IMsFormulaTerm;

Begin

Mb := MetabaseClass.Active;

RubrDescr := Mb.ItemById("FC");

Rubr := RubrDescr.Bind As IRubricator;

MsDescr := Rubr.ModelSpace;

Model := Mb.ItemByIdNamespace("MODEL_ATTR", MsDescr.Key).Edit As IMsModel;

Transform := Model.Transform;

TransformVarables := Transform.Outputs;

TransVar := TransformVarables.Item(0);

TransVar.AttributeId := "UNIT";

FactsAttrs := Rubr.Facts.Attributes;

Attr := FactsAttrs.FindById("UNIT");

DictDescr := Attr.ValuesObject;

ObjList := Transform.ObjectList;

If ObjList.FindByKey(1) = Null

Then

ObjList.Clear;

TransfObj := ObjList.Add(DictDescr);

Else

TransfObj := ObjList.FindByKey(1);

End If;

TermTrue := "@__" + TransfObj.Key.ToString + ":3433"; //3433 - Billions of National Currency

TermFalse := "@__" + TransfObj.Key.ToString + ":3549"; //3549 - National Currency

Determ := Transform.FormulaItem(0).Method As IMsDeterministicTransform;

Expr := Determ.Expression;

Expr.AsString := "";

FormulaTerm := Determ.Operands.Item(0);

Expr.AsString := "iif(" + FormulaTerm.TermToText + "=3433," + TermTrue + "," + TermFalse + ")";

If Not (Expr.Valid)

Then Debug.WriteLine(Expr.ErrorInfo.ErrorMessage);

Else (Model As IMetabaseObject).Save;

End If;

End Sub UserProc;

After executing the example the output variable of model is used for loading in it the values of the UNIT attribute (units). For using the dictionary constant value in the expression, the object with the 1 key (units dictionary) is searched for in the model calculation method objects collection. If the object is not found, it is created. The calculation formula of the determinate equation is set as follows: if the units of the first input variable are Billions of National Currency, the units of output variable are replaced with Billions of National Currency. In case the units of the first input variable are other than Billions of National Currency, the units of output variable are changed to National Currency.

See also:

IMsTransformObjectList