ParameterAsSelection: IMsModelParam;
The ParameterAsSelection property determines a parameter specifying selection.
If the ParameterAsSelection and IMsBranchConditionInSelection.Selection properties are set at the same time, the last specified will be taken into account.
Executing the example requires that the repository contains a modeling container with the MS identifier containing a metamodel with the METAMODEL_BRANCH_PARAM identifier and models with the MODEL_BRANCH_PARAM_SEL, MODEL_BRANCH_PARAM_DEFAULT identifiers. A data source for the modeling container must be a time series database containing a time series attribute with the CITY identifier. This attribute must be a link to the dictionary.
Add links to the Cubes, Dal, Dimensions, Metabase, Ms, Rds,Transform system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsObj, Dict: IMetabaseObjectDescriptor;
pMetaModel: IMsMetaModel;
Chain, pDefaultContents: IMsCalculationChainEntries;
MetaParams: IMsModelParams;
param1, param2: IMsModelParam;
TSDB: IRubricator;
Atrs: IMetaAttributes;
pBranch: IMsCalculationChainBranch;
Case_1, Case_default: IMsModel;
pCase: IMsBranchCase;
pCaseList: IMsBranchCaseList;
pBranchConditions: IMsBranchConditions;
pCondSel: IMsBranchConditionInSelection;
pDimInstance: IDimInstance;
pSelection: IDimSelection;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get modeling container
MsObj := mb.ItemById("MS");
// Get metamodel
pMetaModel := mb.ItemByIdNamespace("METAMODEL_BRANCH_PARAM", MsObj.Key).Edit As IMsMetaModel;
// Get time series database that is used to store
// modeling container data
TSDB := (MsObj.Bind As IMsModelSpace).Rubricator As IRubricator;
// Get time series attributes
Atrs := TSDB.Facts.Attributes;
// Get dictionary, to which the CITY attribute refers
Dict := Atrs.FindById("CITY").ValuesObject;
pDimInstance := Dict.Open(Null) As IDimInstance;
// Get and clear metamodel calculation chain
Chain := pMetaModel.CalculationChain;
Chain.Clear;
// Get and clear metamodel parameters
MetaParams := pMetaModel.Params;
MetaParams.Clear;
// Add the first parameter, which refers to dictionary
param1 := MetaParams.Add;
param1.DataType := DbDataType.Integer;
param1.Hidden := True;
param1.Id := "P_CITY";
param1.Name := "City";
param1.ParamType := TsParamType.Selection;
// Specify that dictionary, which will determine values of parameter
param1.LinkedObject := Dict;
// Set parameter selection
pSelection := pDimInstance.CreateSelection;
pSelection.SelectElement(1, False);
Param1.DefaultValue := pSelection;
// Add the second parameter, which refers to dictionary
param2 := MetaParams.Add;
param2.DataType := DbDataType.Integer;
param2.Hidden := True;
param2.Id := "P_CITY_SEL";
param2.Name := "City (selection)";
param2.ParamType := TsParamType.Selection;
// Specify that dictionary, which will determine values of parameter
param2.LinkedObject := Dict;
// Set parameter selection
pSelection.DeselectAll;
pSelection.SelectElement(2, False);
param2.DefaultValue := pSelection;
// Create a condition node
pBranch := Chain.AddBranch("Condition");
pBranch.Parameter := param1;
// Create a branch, which is executed if none of other branches is executed
pDefaultContents := pBranch.DefaultContents;
// Determine the model that will be calculated in this branch
Case_default := mb.ItemByIdNamespace("MODEL_BRANCH_PARAM_DEFAULT", MsObj.Key).Bind As IMsModel;
pDefaultContents.AddModel(Case_default);
// Create the first branch of condition
pCaseList := pBranch.CaseList;
pCase := pCaseList.Add;
// Determine the model that will be calculated in this branch
Case_1 := mb.ItemByIdNamespace("MODEL_BRANCH_PARAM_SEL", MsObj.Key).Bind As IMsModel;
pCase.Contents.AddModel(Case_1);
// Create a condition of branch calculation
pBranchConditions := pCase.Conditions;
// Determine a type of condition for branch calculation: included into element selection
pCondSel := pBranchConditions.Add(MsBranchConditionType.InSelection) As IMsBranchConditionInSelection;
// Determine that condition is managed by the parameter, which is a selection
pCondSel.ParameterAsSelection := Param2;
// Specify that condition is taken into account
pCondSel.Negation:= False;
// Save metamodel
(pMetaModel As IMetabaseObject).Save;
End Sub UserProc;
After executing the example the condition and two parameters are added to the metamodel. Both parameters are referred to the dictionary. The condition consists of two branches. The first branch is parametric and is calculated if parameter value is included into the specified selection. The second branch is calculated if the previous branch was not calculated.
See also: