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.

Fore 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.

Fore.NET Example

The defined procedure is the Main entry point in the Program module of the .NET assembly. The Cubes, Metabase system assemblies must be imported to this module from the Prognoz.Platform.Interop system assembly.

Public Shared Sub Main(Params: StartParams);

Var
    Mb: IMetabase;
    Rubr: IRubricator;
    ci: IMetabaseObjectCreateInfo;
    ValObj: IMetabaseObjectDescriptor;
    ValidObj: IMetabaseObject;
    ValidFilter: IValidationFilter;
    DateSettings: IValidationDateSettings;
    FilterSett: IValidationFilterSettings;
    Level: IValidationLevel;
    ComparisonValue: IValidationComparisonValue;
    RubrDescr: IMetabaseObjectDescriptor;
Begin
    Mb :=Params.Metabase;
    RubrDescr := Mb.ItemById["WB_WDI_COPY2"];
    Rubr := RubrDescr.Bind() As IRubricator;
    // Create a validation rule
    ci := Mb.CreateCreateInfo();
    ci.ClassId := MetabaseObjectClass.KE_CLASS_VALIDATIONFILTER As integer;
    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.vdoDependsFromData;
    DateSettings := ValidFilter.EndDateSettings;
    DateSettings.DateOptions := ValidationDateOptions.vdoDependsFromData;
    // Set calendar level to calculate the rule
    ValidFilter.Level := DimCalendarLevel.dclYear;
    // Set threshold value for rule exceptions
    ValidFilter.ExceptionsLimit := 500000;
    // Set parameters for calculation of the rule
    FilterSett := ValidFilter.Settings;
    FilterSett.FontColor := GxColorCls.FromName("Red");
    // Set the rule type
    ValidFilter.Kind := ValidationDetailsKind.vdkLevel;
    Level := ValidFilter.Details As IValidationLevel;
    // Set conditions of the rule
    ComparisonValue := Level.ComparisonValue;
    ComparisonValue.ComparisonOperator := ValidationComparisonOperator.vcoMore;
    ComparisonValue.Percentage := False;
    ComparisonValue.Value1 := 100;
    // Save the rule
    ValidObj.Save();
End Sub;

The result of example execution matches with that of the Fore example.

See also:

Examples | Setting Up and Applying Validation Rule