IMsBranchConditionExpression.Expression

Syntax

Expression: IExpression;

Description

The Expression property returns expression for calculating condition.

Comments

For correct working of the condition the expression after calculation must give the result of logical type.

Example

Executing the example requires that the repository contains a modeling container with the MS identifier that contains models with the MODEL_BRANCH_EXPR_F, MODEL_BRANCH_EXPR_S, DEFAULT_MODEL identifiers and a metamodel with the METAMODEL_BRANCH_EXPR identifier.

Add links to the Dal, Dimensions, Metabase, Ms, Xml system assemblies.

Sub UserProc;
Var
    pMetabase: IMetabase;
    pMSKey: Integer;
    pMeta: IMsMetaModel;
    Params: IMsModelParams;
    Param: IMsModelParam;
    pBranch, pBranchCopy: IMsCalculationChainBranch;
    pModel_a, pModel_b: IMsModel;
    pCase, pCaseCopy: IMsBranchCase;
    pCond, pCondCopy: IMsBranchConditionExpression;
    XmlDoc: IXmlDomDocument3;
    el: IXmlDomElement;
Begin
    pMetabase := MetabaseClass.Active;
    //Get modeling container key
    pMSKey := pMetabase.GetObjectKeyById("MS");
    // Get metamodel
    pMeta := pMetabase.ItemByIdNamespace("METAMODEL_BRANCH_EXPR", pMSKey).Edit As IMsMetaModel;
    // Get metamodel parameters collection
    Params := pMeta.Params;
    // Clear parameters collection
    Params.Clear;
    // Add a new integer parameter
    Param := Params.Add;
    Param.Id := "INDICATOR_PARAM";
    Param.Name := "INDICATOR_PARAM";
    Param.DataType := DbDataType.Integer;
    // Clear calculation chain of metamodel
    pMeta.CalculationChain.Clear;
    // Create a condition of metamodel calculation
    pBranch := pMeta.CalculationChain.AddBranch("Calculation condition");
    // Set calendar frequency of condition
    pBranch.Level := DimCalendarLevel.Year;
    // Get the DEFAULT_MODEL model
    pModel_a := pMetabase.ItemByIdNamespace("DEFAULT_MODEL", pMSKey).Bind As IMsModel;
    // Add model to condition
    pBranch.DefaultContents.AddModel(pModel_a);
    // Get the MODEL_BRANCH_EXPR_F model
    pModel_b := pMetabase.ItemByIdNamespace("MODEL_BRANCH_EXPR_F", pMSKey).Bind As IMsModel;
    // Create a new branch of condition
    pCase := pBranch.CaseList.Add;
    // Add the USER_MODEL model to new branch
    pCase.Contents.AddModel(pModel_b);
    // Create a condition of branch calculation
    pCond := pCase.Conditions.Add(MsBranchConditionType.Expression) As IMsBranchConditionExpression;
    pCond.Expression.AsString := "{INDICATOR_PARAM[t]} = 3";
    // Save parameters of condition branch to XML file
    XmlDoc := New FreeThreadedDOMDocument60.Create;
    el := XmlDoc.createElement("Root");
    XmlDoc.appendChild(el);
    pCond.SaveToXml(el);
    XmlDoc.save("C:\ConditionExpr.xml");
    // Create a new metamodel calculation condition 
    pBranchCopy := pMeta.CalculationChain.AddBranch("Calculation condition copy");
    // Create a new branch of condition
    pCaseCopy := pBranchCopy.CaseList.Add;
    // Create a condition of branch calculation
    pCondCopy := pCaseCopy.Conditions.Add(MsBranchConditionType.Expression) As IMsBranchConditionExpression;
    // Load conditions from XML file
    XmlDoc := New FreeThreadedDOMDocument60.Create;
    XmlDoc.load("C:\ConditionExpr.xml");
    el := XmlDoc.selectSingleNode("Root"As IXmlDomElement;
    pCondCopy.LoadFromXml(el);
    // Get the MODEL_BRANCH_EXPR_S model
    pModel_b := pMetabase.ItemByIdNamespace("MODEL_BRANCH_EXPR_S", pMSKey).Bind As IMsModel;
    pCaseCopy.Contents.AddModel(pModel_b);
    // Change branch calculation condition
    pCondCopy.Expression.AsString := "{INDICATOR_PARAM[t]} = 4";
    // Save metamodel
    (pMeta As IMetabaseObject).Save;
End Sub UserProc;

After executing the example the calculation condition will be added to the metamodel: if metamodel parameter value is equal to three, the MODEL_BRANCH_EXPR_F model is calculated, if not, the DEFAULT_MODEL model is calculated. Then a new calculation condition, which is a copy of the first one, is added. The copied condition will be changed: if metamodel parameter value is equal to four, the MODEL_BRANCH_EXPR_S model is calculated, if not, the DEFAULT_MODEL model is calculated.

See also:

IMsBranchConditionExpression