Creating a Validation Rule

Executing the example requires that the repository contains a time series database with the  TSDB identifier containing a new validation rule.

Add links to the following system assemblies:

The example of setting up and implementation of the created validation rule is given on the Setting Up and Applying Validation Rule page.

Example

Sub UserProc;
Var
    Mb: IMetabase;
    Rubr: IRubricator;
    ci: IMetabaseObjectCreateInfo;
    ValObj: IMetabaseObjectDescriptor;
    ValidObj: IMetabaseObject;
    RubrDescr: IMetabaseObjectDescriptor;
    ValidFilter: IValidationFilter;
    DateSettings: IValidationDateSettings;
    FilterSett: IValidationFilterSettings;
    Level: IValidationLevel;
    ComparisonValue: IValidationComparisonValue;
Begin
    Mb := MetabaseClass.Active;
    RubrDescr := Mb.ItemById("TSDB");
    Rubr := RubrDescr.Bind As IRubricator;
    // Create a validation rule
    ci := Mb.CreateCreateInfo;
    ci.ClassId := MetabaseObjectClass.KE_CLASS_VALIDATIONFILTER;
    ci.Parent := RubrDescr;
    ci.Permanent := True;
    ci.IsTemporary := False;
    ci.KeepEdit := True;
    ci.Name := "Comparison with number";
    ci.Id := "NEWVALRULE";
    ValObj := Mb.CreateObject(ci);
    ValidObj := ValObj As IMetabaseObject;
    ValidFilter := ValidObj As IValidationFilter;
    // Set start and end dates of rule calculation
    DateSettings := ValidFilter.StartDateSettings;
    DateSettings.DateOptions := ValidationDateOptions.DependsFromData;
    DateSettings := ValidFilter.EndDateSettings;
    DateSettings.DateOptions := ValidationDateOptions.DependsFromData;
    // Set calendar level to calculate the rule
    ValidFilter.Level := DimCalendarLevel.Year;
    // Set threshold value for rule exceptions
    ValidFilter.ExceptionsLimit := 500000;
    // Set parameters for calculation of the rule
    FilterSett := ValidFilter.Settings;
    // Set the rule type
    ValidFilter.Kind := ValidationDetailsKind.Level;
    Level := ValidFilter.Details As IValidationLevel;
    // Set conditions of the rule
    ComparisonValue := Level.ComparisonValue;
    ComparisonValue.ComparisonOperator := ValidationComparisonOperator.More;
    ComparisonValue.Percentage := False;
    ComparisonValue.Value1 := 50;
    // Save the rule
    ValidObj.Save;
End Sub UserProc;

After executing the example a validation rule with the NEWVALRULE identifier is created in the root catalog of time series database.

See also:

Examples | Setting Up and Applying Validation Rule