Codeunit 20410 Qlty. Result Evaluation

Quality Management, Microsoft.QualityManagement.Configuration.Result

src/Apps/W1/Quality Management/app/src/Configuration/Result/QltyResultEvaluation.Codeunit.al918 lines, Copyright (c) Microsoft Corporation. MIT

// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace Microsoft.QualityManagement.Configuration.Result;using Microsoft.QualityManagement.Configuration.Template.Test;using Microsoft.QualityManagement.Document;using Microsoft.QualityManagement.Utilities;using System.DateTime;using System.Utilities;/// <summary>/// Methods to help with result evaluation./// </summary>codeunit 20410 "Qlty. Result Evaluation"{    TableNo = "Qlty. Inspection Line";    Permissions = tabledata "Qlty. Test" = r,                  tabledata "Qlty. Inspection Result" = r,                  tabledata "Qlty. Inspection Header" = rm,                  tabledata "Qlty. Inspection Line" = rim,                  tabledata "Qlty. I. Result Condit. Conf." = r;    var        IsDefaultNumberTok: Label '<>0', Locked = true;        IsDefaultTextTok: Label '<>''''', Locked = true;        InvalidDataTypeErr: Label 'The value "%1" is not allowed for %2, it is not a %3.', Comment = '%1=the value, %2=field name,%3=field type.';        NotInAllowableValuesErr: Label 'The value "%1" is not allowed for %2, it must be in the range of "%3".', Comment = '%1=the value, %2=field name,%3=field type.';        InvalidAllowableValuesFormatErr: Label 'The allowable values "%1" are not a valid filter expression for %2 of type %3.', Comment = '%1=the allowable values, %2=field name, %3=field type.';    trigger OnRun()    var        OptionalQltyInspectionHeader: Record "Qlty. Inspection Header";    begin        if (not Rec.IsTemporary()) and (Rec."Inspection No." <> '') then            OptionalQltyInspectionHeader.Get(Rec."Inspection No.", Rec."Re-inspection No.");        ValidateQltyInspectionLine(Rec, OptionalQltyInspectionHeader, true);    end;    /// <summary>    /// Evaluates a result with an optional test.    /// The test is used to help with expression evaluation.    /// </summary>    /// <param name="OptionalQltyInspectionHeader">The optional inspection header used to evaluate expressions.</param>    /// <param name="QltyIResultConditConf">The filtered result conditions to evaluate.</param>    /// <param name="QltyTestValueType">The data type used to interpret the test value and conditions.</param>    /// <param name="TestValue">The test value to evaluate.</param>    /// <param name="QltyCaseSensitivity">The case sensitivity used for text and predefined-list comparisons.</param>    /// <returns>The highest-priority result code whose condition matches, or blank when none match.</returns>    internal procedure EvaluateResult(var OptionalQltyInspectionHeader: Record "Qlty. Inspection Header"; var QltyIResultConditConf: Record "Qlty. I. Result Condit. Conf.";        QltyTestValueType: Enum "Qlty. Test Value Type"; TestValue: Text; QltyCaseSensitivity: Enum "Qlty. Case Sensitivity"): Code[20]    var        TempNotUsedOptionalQltyInspectionLine: Record "Qlty. Inspection Line" temporary;    begin        exit(EvaluateResult(OptionalQltyInspectionHeader, TempNotUsedOptionalQltyInspectionLine, QltyIResultConditConf, QltyTestValueType, TestValue, QltyCaseSensitivity));    end;    /// <summary>    /// Evaluates a result with an optional test and inspection line.    /// The test is used to help with expression evaluation.    /// </summary>    /// <param name="OptionalQltyInspectionHeader">The optional inspection header used to evaluate expressions.</param>    /// <param name="OptionalQltyInspectionLine">The optional inspection line used to evaluate expressions.</param>    /// <param name="QltyIResultConditConf">The filtered result conditions to evaluate.</param>    /// <param name="QltyTestValueType">The data type used to interpret the test value and conditions.</param>    /// <param name="TestValue">The test value to evaluate.</param>    /// <param name="QltyCaseSensitivity">The case sensitivity used for text and predefined-list comparisons.</param>    /// <returns>The highest-priority result code whose condition matches, or blank when none match.</returns>    internal procedure EvaluateResult(var OptionalQltyInspectionHeader: Record "Qlty. Inspection Header"; var OptionalQltyInspectionLine: Record "Qlty. Inspection Line"; var QltyIResultConditConf: Record "Qlty. I. Result Condit. Conf."; QltyTestValueType: Enum "Qlty. Test Value Type"; TestValue: Text; QltyCaseSensitivity: Enum "Qlty. Case Sensitivity") Result: Code[20]    var        QltyInspectionResult: Record "Qlty. Inspection Result";        TempHighestQltyIResultConditConf: Record "Qlty. I. Result Condit. Conf." temporary;        QltyBooleanParsing: Codeunit "Qlty. Boolean Parsing";        QltyExpressionMgmt: Codeunit "Qlty. Expression Mgmt.";        LoopConditionMet: Boolean;        AnyConditionMet: Boolean;        IsHandled: Boolean;        Small: Text[250];        Condition: Text;    begin        OnBeforeEvaluateResult(QltyIResultConditConf, QltyTestValueType, TestValue, Result, IsHandled);        if IsHandled then            exit;        QltyInspectionResult.SetCurrentKey("Evaluation Sequence");        QltyInspectionResult.Ascending();        if not QltyInspectionResult.FindSet() then            exit;        repeat            QltyIResultConditConf.SetRange("Result Code", QltyInspectionResult.Code);            if QltyIResultConditConf.FindSet() then                repeat                    LoopConditionMet := false;                    Condition := QltyIResultConditConf.Condition;                    if Condition.Contains('[') then                        Condition := QltyExpressionMgmt.EvaluateTextExpression(Condition, OptionalQltyInspectionHeader, OptionalQltyInspectionLine);                    case QltyTestValueType of                        QltyTestValueType::"Value Type Decimal":                            LoopConditionMet := CheckIfValueIsDecimal(TestValue, Condition);                        QltyTestValueType::"Value Type Integer":                            LoopConditionMet := CheckIfValueIsInteger(TestValue, Condition);                        QltyTestValueType::"Value Type Boolean":                            if QltyBooleanParsing.CanTextBeInterpretedAsBooleanIsh(TestValue) and                               QltyBooleanParsing.CanTextBeInterpretedAsBooleanIsh(Condition)                            then                                LoopConditionMet := QltyBooleanParsing.GetBooleanFor(TestValue) = QltyBooleanParsing.GetBooleanFor(Condition)                            else                                LoopConditionMet := CheckIfValueIsString(TestValue, Condition, QltyCaseSensitivity);                        QltyTestValueType::"Value Type Option", QltyTestValueType::"Value Type Table Lookup":                            LoopConditionMet := CheckIfValueIsInPredefinedList(TestValue, Condition, QltyCaseSensitivity);                        QltyTestValueType::"Value Type Text", QltyTestValueType::"Value Type Text Expression":                            LoopConditionMet := CheckIfValueIsString(TestValue, Condition, QltyCaseSensitivity);                        QltyTestValueType::"Value Type Date":                            begin                                Small := CopyStr(TestValue, 1, MaxStrLen(Small));                                LoopConditionMet := CheckIfValueIsDate(Small, Condition, false);                                TestValue := Small;                            end;                        QltyTestValueType::"Value Type DateTime":                            begin                                Small := CopyStr(TestValue, 1, MaxStrLen(Small));                                LoopConditionMet := CheckIfValueIsDateTime(Small, Condition, false);                                TestValue := Small;                            end;                        QltyTestValueType::"Value Type Label":                            LoopConditionMet := true;                    end;                    if LoopConditionMet then begin                        AnyConditionMet := true;                        TempHighestQltyIResultConditConf := QltyIResultConditConf;                    end;                until QltyIResultConditConf.Next() = 0;        until QltyInspectionResult.Next() = 0;        OnAfterEvaluateResult(QltyIResultConditConf, QltyTestValueType, TestValue, Result, TempHighestQltyIResultConditConf);        if AnyConditionMet then            exit(TempHighestQltyIResultConditConf."Result Code");    end;    /// <summary>    /// Call this procedure to validate the inspection line.    /// </summary>    /// <param name="QltyInspectionLine">The inspection line to validate and update.</param>    internal procedure ValidateQltyInspectionLine(var QltyInspectionLine: Record "Qlty. Inspection Line")    var        OptionalQltyInspectionHeader: Record "Qlty. Inspection Header";    begin        if (not QltyInspectionLine.IsTemporary()) and (QltyInspectionLine."Inspection No." <> '') then            if OptionalQltyInspectionHeader.Get(QltyInspectionLine."Inspection No.", QltyInspectionLine."Re-inspection No.") then;        ValidateQltyInspectionLine(QltyInspectionLine, OptionalQltyInspectionHeader, true);    end;    /// <summary>    /// This will *not* modify the inspection line.    /// This will only try and validate the inspection line itself.    /// </summary>    /// <param name="QltyInspectionLine">The inspection line to validate without persisting changes.</param>    /// <param name="OptionalQltyInspectionHeader">The optional inspection header used for expression context.</param>    [TryFunction]    internal procedure TryValidateQltyInspectionLine(var QltyInspectionLine: Record "Qlty. Inspection Line"; var OptionalQltyInspectionHeader: Record "Qlty. Inspection Header")    begin        ValidateQltyInspectionLine(QltyInspectionLine, OptionalQltyInspectionHeader, false);    end;    /// <summary>    /// Call this procedure to validate the inspection line for the given test.    /// </summary>    /// <param name="QltyInspectionLine">The inspection line to validate.</param>    /// <param name="OptionalQltyInspectionHeader">The optional inspection header used for expression context and result updates.</param>    /// <param name="Modify">Set to true to modify the result(default), false to avoid modifying.</param>    procedure ValidateQltyInspectionLine(var QltyInspectionLine: Record "Qlty. Inspection Line"; var OptionalQltyInspectionHeader: Record "Qlty. Inspection Header"; Modify: Boolean)    begin        ValidateInspectionLineWithAllowableValues(QltyInspectionLine, OptionalQltyInspectionHeader, true, Modify);    end;    /// <summary>    /// Validates optional allowable values, evaluates the line result, sets its failure state, and optionally persists line and header updates.    /// </summary>    /// <param name="QltyInspectionLine">The inspection line to evaluate and update.</param>    /// <param name="OptionalQltyInspectionHeader">The optional header used for expressions and aggregate result updates.</param>    /// <param name="CheckForAllowableValues">Specifies whether the test value is validated against allowable values first.</param>    /// <param name="UpdateHeader">Specifies whether line and header changes are persisted.</param>    internal procedure ValidateInspectionLineWithAllowableValues(var QltyInspectionLine: Record "Qlty. Inspection Line"; var OptionalQltyInspectionHeader: Record "Qlty. Inspection Header"; CheckForAllowableValues: Boolean; UpdateHeader: Boolean)    var        QltyTest: Record "Qlty. Test";        QltyInspectionResult: Record "Qlty. Inspection Result";        QltyIResultConditConf: Record "Qlty. I. Result Condit. Conf.";        Result: Code[20];        QltyCaseSensitivity: Enum "Qlty. Case Sensitivity";    begin        QltyInspectionLine.CalcFields("Test Value Type");        if CheckForAllowableValues then            ValidateAllowableValuesOnInspectionLine(QltyInspectionLine, OptionalQltyInspectionHeader);        GetTestResultConditionConfigFilters(QltyInspectionLine, QltyIResultConditConf);        QltyCaseSensitivity := QltyCaseSensitivity::Sensitive;        if QltyTest.Get(QltyInspectionLine."Test Code") then            QltyCaseSensitivity := QltyTest."Case Sensitive";        Result := EvaluateResult(OptionalQltyInspectionHeader, QltyInspectionLine, QltyIResultConditConf, QltyInspectionLine."Test Value Type", QltyInspectionLine."Test Value", QltyCaseSensitivity);        QltyInspectionLine."Failure State" := QltyInspectionLine."Failure State"::" ";        if Result <> '' then begin            QltyInspectionResult.Get(Result);            if QltyInspectionResult."Result Category" = QltyInspectionResult."Result Category"::"Not acceptable" then                QltyInspectionLine."Failure State" := QltyInspectionLine."Failure State"::"Failed from Acceptance Criteria";        end;        QltyInspectionLine.Validate("Result Code", Result);        if UpdateHeader then            QltyInspectionLine.Modify(true);        if (not QltyInspectionLine.IsTemporary()) and (OptionalQltyInspectionHeader."No." <> '') and (QltyInspectionLine."Inspection No." <> '') then begin            OptionalQltyInspectionHeader.UpdateResultFromLines();            OptionalQltyInspectionHeader.Validate("Result Code");            if UpdateHeader and not IsNullGuid(OptionalQltyInspectionHeader.SystemId) then                if OptionalQltyInspectionHeader.Modify(true) then;        end;    end;    /// <summary>    /// Filters result conditions to the specified inspection line and test.    /// </summary>    /// <param name="QltyInspectionLine">The inspection line that supplies the condition key.</param>    /// <param name="TemplateLineQltyIResultConditConf">The condition record on which inspection filters are set.</param>    internal procedure GetInspectionLineConfigFilters(var QltyInspectionLine: Record "Qlty. Inspection Line"; var TemplateLineQltyIResultConditConf: Record "Qlty. I. Result Condit. Conf.")    begin        TemplateLineQltyIResultConditConf.SetRange("Condition Type", TemplateLineQltyIResultConditConf."Condition Type"::Inspection);        TemplateLineQltyIResultConditConf.SetRange("Target Code", QltyInspectionLine."Inspection No.");        TemplateLineQltyIResultConditConf.SetRange("Target Re-inspection No.", QltyInspectionLine."Re-inspection No.");        TemplateLineQltyIResultConditConf.SetRange("Target Line No.", QltyInspectionLine."Line No.");        TemplateLineQltyIResultConditConf.SetRange("Test Code", QltyInspectionLine."Test Code");    end;    /// <summary>    /// Selects inspection, template, or test result conditions for an inspection line in precedence order.    /// </summary>    /// <param name="QltyInspectionLine">The inspection line whose conditions are selected.</param>    /// <param name="QltyIResultConditConf">The condition record that receives the selected filters.</param>    local procedure GetTestResultConditionConfigFilters(var QltyInspectionLine: Record "Qlty. Inspection Line"; var QltyIResultConditConf: Record "Qlty. I. Result Condit. Conf.")    begin        QltyIResultConditConf.Reset();        QltyIResultConditConf.SetRange("Condition Type", QltyIResultConditConf."Condition Type"::Inspection);        QltyIResultConditConf.SetRange("Target Code", QltyInspectionLine."Inspection No.");        QltyIResultConditConf.SetRange("Target Re-inspection No.", QltyInspectionLine."Re-inspection No.");        QltyIResultConditConf.SetRange("Target Line No.", QltyInspectionLine."Line No.");        QltyIResultConditConf.SetRange("Test Code", QltyInspectionLine."Test Code");        if QltyIResultConditConf.IsEmpty() then begin            QltyIResultConditConf.SetRange("Condition Type", QltyIResultConditConf."Condition Type"::Template);            QltyIResultConditConf.SetRange("Target Code", QltyInspectionLine."Template Code");            QltyIResultConditConf.SetRange("Target Re-inspection No.");            QltyIResultConditConf.SetRange("Target Line No.", QltyInspectionLine."Template Line No.");            QltyIResultConditConf.SetRange("Test Code", QltyInspectionLine."Test Code");            if QltyIResultConditConf.IsEmpty() then begin                QltyIResultConditConf.SetRange("Condition Type", QltyIResultConditConf."Condition Type"::Test);                QltyIResultConditConf.SetRange("Target Code", QltyInspectionLine."Test Code");                QltyIResultConditConf.SetRange("Target Re-inspection No.");                QltyIResultConditConf.SetRange("Target Line No.");                QltyIResultConditConf.SetRange("Test Code", QltyInspectionLine."Test Code");            end;        end;    end;    /// <summary>    /// Validates and normalizes an inspection line test value against its allowable values.    /// </summary>    /// <param name="QltyInspectionLine">The inspection line whose test value is validated.</param>    /// <param name="OptionalQltyInspectionHeader">The optional header used to resolve allowable-value expressions.</param>    local procedure ValidateAllowableValuesOnInspectionLine(var QltyInspectionLine: Record "Qlty. Inspection Line"; var OptionalQltyInspectionHeader: Record "Qlty. Inspection Header")    var        QltyTest: Record "Qlty. Test";        TempBufferQltyTestLookupValue: Record "Qlty. Test Lookup Value" temporary;        QltyExpressionMgmt: Codeunit "Qlty. Expression Mgmt.";        QltyCaseSensitivity: Enum "Qlty. Case Sensitivity";        TestNameForError: Text;        AllowableValues: Text;    begin        QltyInspectionLine.CalcFields("Test Value Type");        if QltyInspectionLine."Test Value" = '' then            exit;        if QltyInspectionLine.Description <> '' then            TestNameForError := QltyInspectionLine.Description        else            TestNameForError := QltyInspectionLine."Test Code";        if QltyInspectionLine."Test Value Type" in [QltyInspectionLine."Test Value Type"::"Value Type Option", QltyInspectionLine."Test Value Type"::"Value Type Table Lookup"] then            QltyInspectionLine.CollectAllowableValues(TempBufferQltyTestLookupValue);        QltyCaseSensitivity := QltyCaseSensitivity::Sensitive;        if QltyTest.Get(QltyInspectionLine."Test Code") then            QltyCaseSensitivity := QltyTest."Case Sensitive";        if QltyInspectionLine.IsTemporary() and (QltyInspectionLine."Test Value Type" in [QltyInspectionLine."Test Value Type"::"Value Type Option", QltyInspectionLine."Test Value Type"::"Value Type Table Lookup"]) then            QltyCaseSensitivity := QltyCaseSensitivity::Insensitive;        AllowableValues := QltyInspectionLine."Allowable Values";        if AllowableValues.Contains('[') then            AllowableValues := QltyExpressionMgmt.EvaluateTextExpression(AllowableValues, OptionalQltyInspectionHeader, QltyInspectionLine);        ValidateAllowableValuesOnText(            TestNameForError,            QltyInspectionLine."Test Value",            AllowableValues,            QltyInspectionLine."Test Value Type",            TempBufferQltyTestLookupValue,            QltyCaseSensitivity);    end;    /// <summary>    /// Validates and normalizes a test default value against its allowable values without inspection context.    /// </summary>    /// <param name="QltyTest">The test whose default value is validated.</param>    internal procedure ValidateAllowableValuesOnTest(var QltyTest: Record "Qlty. Test")    var        TempDummyQltyInspectionHeader: Record "Qlty. Inspection Header" temporary;        TempDummyQltyInspectionLine: Record "Qlty. Inspection Line" temporary;    begin        ValidateAllowableValuesOnTest(QltyTest, TempDummyQltyInspectionHeader, TempDummyQltyInspectionLine);    end;    /// <summary>    /// Validates and normalizes a test default value with optional inspection header context.    /// </summary>    /// <param name="QltyTest">The test whose default value is validated.</param>    /// <param name="OptionalContextQltyInspectionHeader">The optional header used to collect or resolve allowable values.</param>    internal procedure ValidateAllowableValuesOnTest(var QltyTest: Record "Qlty. Test"; var OptionalContextQltyInspectionHeader: Record "Qlty. Inspection Header")    var        TempDummyQltyInspectionLine: Record "Qlty. Inspection Line" temporary;    begin        ValidateAllowableValuesOnTest(QltyTest, OptionalContextQltyInspectionHeader, TempDummyQltyInspectionLine);    end;    /// <summary>    /// Validates and normalizes a test default value with optional inspection header and line context.    /// </summary>    /// <param name="QltyTest">The test whose default value is validated.</param>    /// <param name="OptionalContextQltyInspectionHeader">The optional header used to collect or resolve allowable values.</param>    /// <param name="OptionalContextQltyInspectionLine">The optional line used to collect or resolve allowable values.</param>    internal procedure ValidateAllowableValuesOnTest(var QltyTest: Record "Qlty. Test"; var OptionalContextQltyInspectionHeader: Record "Qlty. Inspection Header"; var OptionalContextQltyInspectionLine: Record "Qlty. Inspection Line")    var        TempBufferQltyTestLookupValue: Record "Qlty. Test Lookup Value" temporary;        QltyCaseSensitivity: Enum "Qlty. Case Sensitivity";        TestNameForError: Text;    begin        if QltyTest.Description <> '' then            TestNameForError := QltyTest.Description        else            TestNameForError := QltyTest.Code;        if QltyTest."Test Value Type" in [QltyTest."Test Value Type"::"Value Type Option", QltyTest."Test Value Type"::"Value Type Table Lookup"] then            QltyTest.CollectAllowableValues(OptionalContextQltyInspectionHeader, OptionalContextQltyInspectionLine, TempBufferQltyTestLookupValue, QltyTest."Default Value");        QltyCaseSensitivity := QltyTest."Case Sensitive";        if QltyTest.IsTemporary() and (QltyTest."Test Value Type" in [QltyTest."Test Value Type"::"Value Type Option", QltyTest."Test Value Type"::"Value Type Table Lookup"]) then            QltyCaseSensitivity := QltyCaseSensitivity::Insensitive;        ValidateAllowableValuesOnText(TestNameForError, QltyTest."Default Value", QltyTest."Allowable Values", QltyTest."Test Value Type", TempBufferQltyTestLookupValue, QltyCaseSensitivity);    end;    /// <summary>    /// Validates that the allowable values expression is a valid filter for the given test value type.    /// </summary>    /// <param name="QltyTest">The test whose allowable values expression should be validated.</param>    internal procedure ValidateAllowableValuesFormat(var QltyTest: Record "Qlty. Test")    var        TestNameForError: Text;    begin        if QltyTest.Description <> '' then            TestNameForError := QltyTest.Description        else            TestNameForError := QltyTest.Code;        ValidateAllowableValuesFormat(TestNameForError, QltyTest."Allowable Values", QltyTest."Test Value Type");    end;    /// <summary>    /// Validates that the allowable values expression is a valid filter for the given test value type.    /// </summary>    /// <param name="NumberOrNameOfTestNameForError">Friendly identifier used in error messages.</param>    /// <param name="AllowableValues">The allowable values filter expression to validate.</param>    /// <param name="QltyTestValueType">The test value type that the filter expression must match.</param>    local procedure ValidateAllowableValuesFormat(NumberOrNameOfTestNameForError: Text; AllowableValues: Text; QltyTestValueType: Enum "Qlty. Test Value Type")    var        IsValid: Boolean;    begin        if AllowableValues = '' then            exit;        if IsBlankOrEmptyCondition(AllowableValues) then            exit;        if IsAnythingExceptEmptyCondition(AllowableValues) then            exit;        // Allowable values may contain inline expressions like [Field] that are resolved at evaluation time.        // Defer validation until resolution.        if AllowableValues.Contains('[') then            exit;        IsValid := true;        case QltyTestValueType of            QltyTestValueType::"Value Type Decimal":                IsValid := TryApplyDecimalFilter(AllowableValues);            QltyTestValueType::"Value Type Integer":                IsValid := TryApplyIntegerFilter(AllowableValues);            QltyTestValueType::"Value Type Boolean":                IsValid := TryApplyBooleanFilter(AllowableValues);            QltyTestValueType::"Value Type Date":                IsValid := TryApplyDateFilter(AllowableValues);            QltyTestValueType::"Value Type DateTime":                IsValid := TryApplyDateTimeFilter(AllowableValues);        end;        if not IsValid then            Error(InvalidAllowableValuesFormatErr, AllowableValues, NumberOrNameOfTestNameForError, QltyTestValueType);    end;    /// <summary>    /// Tests whether an expression can be applied as a decimal filter.    /// </summary>    /// <param name="FilterExpression">The decimal filter expression to test.</param>    [TryFunction]    local procedure TryApplyDecimalFilter(FilterExpression: Text)    var        TempQltyInspectionLine: Record "Qlty. Inspection Line" temporary;    begin        TempQltyInspectionLine.SetFilter("Derived Numeric Value", FilterExpression);        if TempQltyInspectionLine.IsEmpty() then;    end;    /// <summary>    /// Tests whether an expression can be applied as an integer filter.    /// </summary>    /// <param name="FilterExpression">The integer filter expression to test.</param>    [TryFunction]    local procedure TryApplyIntegerFilter(FilterExpression: Text)    var        TempInteger: Record "Integer" temporary;    begin        TempInteger.SetFilter(Number, FilterExpression);        if TempInteger.IsEmpty() then;    end;    /// <summary>    /// Tests whether an expression represents a supported Boolean value.    /// </summary>    /// <param name="FilterExpression">The Boolean expression to test.</param>    [TryFunction]    local procedure TryApplyBooleanFilter(FilterExpression: Text)    var        QltyBooleanParsing: Codeunit "Qlty. Boolean Parsing";    begin        // Valid boolean allowable values are: Yes, No, True, False, 1, 0, On, Off (and variations)        if not QltyBooleanParsing.CanTextBeInterpretedAsBooleanIsh(FilterExpression) then            Error(InvalidAllowableValuesFormatErr, FilterExpression, '', 'Boolean');    end;    /// <summary>    /// Tests whether an expression can be applied as a date filter.    /// </summary>    /// <param name="FilterExpression">The date filter expression to test.</param>    [TryFunction]    local procedure TryApplyDateFilter(FilterExpression: Text)    var        TempDateLookupBuffer: Record "Date Lookup Buffer" temporary;    begin        TempDateLookupBuffer.SetFilter("Period Start", FilterExpression);        if TempDateLookupBuffer.IsEmpty() then;    end;    /// <summary>    /// Tests whether an expression can be applied as a date-time filter.    /// </summary>    /// <param name="FilterExpression">The date-time filter expression to test.</param>    [TryFunction]    local procedure TryApplyDateTimeFilter(FilterExpression: Text)    var        TempQltyInspectionHeader: Record "Qlty. Inspection Header" temporary;    begin        TempQltyInspectionHeader.SetFilter("Finished Date", FilterExpression);        if TempQltyInspectionHeader.IsEmpty() then;    end;    /// <summary>    /// Validates and normalizes text according to a test value type, allowable expression, and lookup values.    /// </summary>    /// <param name="NumberOrNameOfTestNameForError">The test identifier used in validation errors.</param>    /// <param name="TextToValidate">The value to validate and normalize.</param>    /// <param name="AllowableValues">The allowable values expression.</param>    /// <param name="QltyTestValueType">The data type used to interpret the value.</param>    /// <param name="TempBufferQltyTestLookupValue">The allowable lookup values for option and table lookup tests.</param>    /// <param name="QltyCaseSensitivity">The case sensitivity used for text matching.</param>    local procedure ValidateAllowableValuesOnText(NumberOrNameOfTestNameForError: Text; var TextToValidate: Text[250]; AllowableValues: Text; QltyTestValueType: Enum "Qlty. Test Value Type"; var TempBufferQltyTestLookupValue: Record "Qlty. Test Lookup Value" temporary; QltyCaseSensitivity: Enum "Qlty. Case Sensitivity")    var        QltyBooleanParsing: Codeunit "Qlty. Boolean Parsing";        QltyLocalization: Codeunit "Qlty. Localization";        QltyResultEvaluation: Codeunit "Qlty. Result Evaluation";        ValueAsDecimal: Decimal;        ValueAsInteger: Integer;        DateAndTimeValue: DateTime;        DateOnlyValue: Date;        IsHandled: Boolean;    begin        OnBeforeValidateAllowableValuesOnText(NumberOrNameOfTestNameForError, TextToValidate, AllowableValues, QltyTestValueType, TempBufferQltyTestLookupValue, QltyCaseSensitivity, IsHandled);        if IsHandled then            exit;        if TextToValidate = '' then            exit;        case QltyTestValueType of            QltyTestValueType::"Value Type Decimal":                if not (IsBlankOrEmptyCondition(AllowableValues) and (TextToValidate = '')) then begin                    if (TextToValidate <> '') and (not Evaluate(ValueAsDecimal, TextToValidate)) then                        Error(InvalidDataTypeErr, TextToValidate, NumberOrNameOfTestNameForError, QltyTestValueType);                    if not QltyResultEvaluation.CheckIfValueIsDecimal(TextToValidate, AllowableValues) then                        Error(NotInAllowableValuesErr, TextToValidate, NumberOrNameOfTestNameForError, AllowableValues);                end;            QltyTestValueType::"Value Type Integer":                if not (IsBlankOrEmptyCondition(AllowableValues) and (TextToValidate = '')) then begin                    if (TextToValidate <> '') and (not Evaluate(ValueAsInteger, TextToValidate)) then                        Error(InvalidDataTypeErr, TextToValidate, NumberOrNameOfTestNameForError, QltyTestValueType);                    if not QltyResultEvaluation.CheckIfValueIsInteger(TextToValidate, AllowableValues) then                        Error(NotInAllowableValuesErr, TextToValidate, NumberOrNameOfTestNameForError, AllowableValues);                end;            QltyTestValueType::"Value Type DateTime":                if not (IsBlankOrEmptyCondition(AllowableValues) and (TextToValidate = '')) then begin                    if (TextToValidate <> '') and (not Evaluate(DateAndTimeValue, TextToValidate)) then                        Error(InvalidDataTypeErr, TextToValidate, NumberOrNameOfTestNameForError, QltyTestValueType);                    if not QltyResultEvaluation.CheckIfValueIsDateTime(TextToValidate, AllowableValues, true) then                        Error(NotInAllowableValuesErr, TextToValidate, NumberOrNameOfTestNameForError, QltyTestValueType);                end;            QltyTestValueType::"Value Type Date":                if not (IsBlankOrEmptyCondition(AllowableValues) and (TextToValidate = '')) then begin                    if (TextToValidate <> '') and (not Evaluate(DateOnlyValue, TextToValidate)) then                        Error(InvalidDataTypeErr, TextToValidate, NumberOrNameOfTestNameForError, QltyTestValueType);                    if not QltyResultEvaluation.CheckIfValueIsDate(TextToValidate, AllowableValues, true) then                        Error(NotInAllowableValuesErr, TextToValidate, NumberOrNameOfTestNameForError, AllowableValues);                end;            QltyTestValueType::"Value Type Boolean":                begin                    if not (IsBlankOrEmptyCondition(AllowableValues) and (TextToValidate = '')) then                        if QltyBooleanParsing.GetBooleanFor(TextToValidate) then                            TextToValidate := QltyLocalization.GetTranslatedYes()                        else                            TextToValidate := QltyLocalization.GetTranslatedNo();                    if (AllowableValues <> '') and (QltyBooleanParsing.CanTextBeInterpretedAsBooleanIsh(AllowableValues)) then begin                        if not QltyBooleanParsing.GetBooleanFor(TextToValidate) = QltyBooleanParsing.GetBooleanFor(AllowableValues) then                            Error(NotInAllowableValuesErr, TextToValidate, NumberOrNameOfTestNameForError, AllowableValues);                    end else                        if not (TextToValidate in [QltyLocalization.GetTranslatedYes(), QltyLocalization.GetTranslatedNo(), '']) then                            Error(NotInAllowableValuesErr, TextToValidate, NumberOrNameOfTestNameForError, AllowableValues);                end;            QltyTestValueType::"Value Type Text":                if not (IsBlankOrEmptyCondition(AllowableValues) and (TextToValidate = '')) then                    if not QltyResultEvaluation.CheckIfValueIsString(TextToValidate, ConvertStr(AllowableValues, ',', '|'), QltyCaseSensitivity) then                        Error(NotInAllowableValuesErr, TextToValidate, NumberOrNameOfTestNameForError, AllowableValues);            QltyTestValueType::"Value Type Option",            QltyTestValueType::"Value Type Table Lookup":                begin                    TextToValidate := CopyStr(TextToValidate.Trim(), 1, MaxStrLen(TextToValidate));                    TempBufferQltyTestLookupValue.Reset();                    TempBufferQltyTestLookupValue.SetRange("Custom 1", TextToValidate);                    if TempBufferQltyTestLookupValue.IsEmpty() and (QltyCaseSensitivity = QltyCaseSensitivity::Insensitive) then begin                        TempBufferQltyTestLookupValue.Reset();                        TempBufferQltyTestLookupValue.SetRange("Custom 2", TextToValidate.ToLower());                    end;                    if TempBufferQltyTestLookupValue.IsEmpty() then begin                        TempBufferQltyTestLookupValue.Reset();                        if QltyCaseSensitivity = QltyCaseSensitivity::Insensitive then                            TempBufferQltyTestLookupValue.SetFilter("Custom 2", '%1', '@' + TextToValidate.ToLower() + '*')                        else                            TempBufferQltyTestLookupValue.SetFilter("Custom 1", '%1', TextToValidate + '*');                    end;                    if TempBufferQltyTestLookupValue.Count() = 1 then begin                        TempBufferQltyTestLookupValue.FindFirst();                        TextToValidate := CopyStr(TempBufferQltyTestLookupValue."Custom 1", 1, MaxStrLen(TextToValidate));                    end else                        Error(NotInAllowableValuesErr, TextToValidate, NumberOrNameOfTestNameForError, AllowableValues);                end;        end;        OnAfterValidateAllowableValuesOnText(NumberOrNameOfTestNameForError, TextToValidate, AllowableValues, QltyTestValueType, TempBufferQltyTestLookupValue, QltyCaseSensitivity);    end;    /// <summary>    /// Checks whether a decimal text value satisfies an acceptable-value filter.    /// </summary>    /// <param name="ValueToCheck">The decimal text value to evaluate.</param>    /// <param name="AcceptableValue">The acceptable-value filter expression.</param>    /// <returns>True if the value satisfies the filter.</returns>    internal procedure CheckIfValueIsDecimal(ValueToCheck: Text; AcceptableValue: Text): Boolean    var        TempNumericalQltyInspectionLine: Record "Qlty. Inspection Line" temporary;        ValueAsDecimal: Decimal;    begin        if ValueToCheck = '' then            ValueAsDecimal := 0        else            Evaluate(ValueAsDecimal, ValueToCheck);        if (AcceptableValue = '') and (ValueToCheck <> '') then            exit(true);        if AcceptableValue = '<>''''' then            AcceptableValue := '<>0';        if (ValueToCheck = '') and not (AcceptableValue in ['', '=''''', '<>0']) then            exit(false);        TempNumericalQltyInspectionLine."Derived Numeric Value" := ValueAsDecimal;        if TempNumericalQltyInspectionLine.Insert(false) then;        TempNumericalQltyInspectionLine.SetFilter("Derived Numeric Value", AcceptableValue);        exit(not TempNumericalQltyInspectionLine.IsEmpty());    end;    /// <summary>    /// Checks whether an integer text value satisfies an acceptable-value filter.    /// </summary>    /// <param name="ValueToCheck">The integer text value to evaluate.</param>    /// <param name="AcceptableValue">The acceptable-value filter expression.</param>    /// <returns>True if the value satisfies the filter.</returns>    internal procedure CheckIfValueIsInteger(ValueToCheck: Text; AcceptableValue: Text): Boolean    var        TempInteger: Record "Integer" temporary;        ValueAsInteger: Integer;    begin        if ValueToCheck = '' then            ValueAsInteger := 0        else            Evaluate(ValueAsInteger, ValueToCheck);        if (AcceptableValue = '') and (ValueToCheck <> '') then            exit(true);        if AcceptableValue = '<>''''' then            AcceptableValue := '<>0';        if (ValueToCheck = '') and not (AcceptableValue in ['', '=''''', '<>0']) then            exit(false);        TempInteger.Number := ValueAsInteger;        TempInteger.Insert();        TempInteger.SetFilter(Number, AcceptableValue);        exit(not TempInteger.IsEmpty());    end;    /// <summary>    /// Checks whether a condition accepts blank or any value.    /// </summary>    /// <param name="AcceptableValue">The condition to inspect.</param>    /// <returns>True if the condition is blank or contains only the supported blank form.</returns>    local procedure IsBlankOrEmptyCondition(AcceptableValue: Text) Result: Boolean    begin        Result := AcceptableValue in ['', '  '];    end;    /// <summary>    /// Checks whether a condition represents any non-empty value.    /// </summary>    /// <param name="AcceptableValue">The condition to inspect.</param>    /// <returns>True if the condition is a default non-empty condition.</returns>    local procedure IsAnythingExceptEmptyCondition(AcceptableValue: Text) Result: Boolean    begin        Result := AcceptableValue in [IsDefaultNumberTok, IsDefaultTextTok];    end;    /// <summary>    /// Checks a date-time text value against a filter and optionally normalizes valid text.    /// </summary>    /// <param name="ValueToCheck">The date-time text to evaluate and optionally normalize.</param>    /// <param name="AcceptableValue">The acceptable-value filter expression.</param>    /// <param name="AdjustValueIfGood">Specifies whether valid text is converted to invariant format.</param>    /// <returns>True if the value satisfies the condition.</returns>    internal procedure CheckIfValueIsDateTime(var ValueToCheck: Text[250]; AcceptableValue: Text; AdjustValueIfGood: Boolean) IsGood: Boolean    var        TempQltyInspectionHeader: Record "Qlty. Inspection Header" temporary;        ValueAsDateTime: DateTime;    begin        if ValueToCheck = '' then            ValueAsDateTime := 0DT        else            Evaluate(ValueAsDateTime, ValueToCheck);        if IsAnythingExceptEmptyCondition(AcceptableValue) then            if ValueToCheck <> '' then begin                IsGood := true;                if AdjustValueIfGood then                    ValueToCheck := CopyStr(Format(ValueAsDateTime, 0, 9), 1, MaxStrLen(ValueToCheck));                exit(IsGood);            end else begin                IsGood := false;                exit(IsGood);            end;        if IsBlankOrEmptyCondition(AcceptableValue) then            if ValueToCheck <> '' then begin                IsGood := true;                if AdjustValueIfGood then                    ValueToCheck := CopyStr(Format(ValueAsDateTime, 0, 9), 1, MaxStrLen(ValueToCheck));                exit(IsGood);            end else begin                IsGood := true;                exit(IsGood);            end;        TempQltyInspectionHeader."Finished Date" := ValueAsDateTime;        TempQltyInspectionHeader.Insert();        TempQltyInspectionHeader.SetFilter("Finished Date", AcceptableValue);        IsGood := not TempQltyInspectionHeader.IsEmpty();        if IsGood and AdjustValueIfGood then            ValueToCheck := CopyStr(Format(ValueAsDateTime, 0, 9), 1, MaxStrLen(ValueToCheck));        exit(IsGood);    end;    /// <summary>    /// Checks a date text value against a filter and optionally normalizes valid text.    /// </summary>    /// <param name="ValueToCheck">The date text to evaluate and optionally normalize.</param>    /// <param name="AcceptableValue">The acceptable-value filter expression.</param>    /// <param name="AdjustValueIfGood">Specifies whether valid text is converted to invariant format.</param>    /// <returns>True if the value satisfies the condition.</returns>    internal procedure CheckIfValueIsDate(var ValueToCheck: Text[250]; AcceptableValue: Text; AdjustValueIfGood: Boolean) IsGood: Boolean    var        TempDateLookupBuffer: Record "Date Lookup Buffer" temporary;        ValueAsDate: Date;    begin        if ValueToCheck = '' then            ValueAsDate := 0D        else            Evaluate(ValueAsDate, ValueToCheck);        if IsAnythingExceptEmptyCondition(AcceptableValue) then            if ValueToCheck <> '' then begin                IsGood := true;                if AdjustValueIfGood then                    ValueToCheck := CopyStr(Format(ValueAsDate, 0, 9), 1, MaxStrLen(ValueToCheck));                exit(IsGood);            end else begin                IsGood := false;                exit(IsGood);            end;        if IsBlankOrEmptyCondition(AcceptableValue) then            if ValueToCheck <> '' then begin                IsGood := true;                if AdjustValueIfGood then                    ValueToCheck := CopyStr(Format(ValueAsDate, 0, 9), 1, MaxStrLen(ValueToCheck));                exit(IsGood);            end else begin                IsGood := true;                exit(IsGood);            end;        TempDateLookupBuffer."Period Start" := ValueAsDate;        TempDateLookupBuffer.Insert();        TempDateLookupBuffer.SetFilter("Period Start", AcceptableValue);        IsGood := not TempDateLookupBuffer.IsEmpty();        if IsGood and AdjustValueIfGood then            ValueToCheck := CopyStr(Format(ValueAsDate, 0, 9), 1, MaxStrLen(ValueToCheck));        exit(IsGood);    end;    /// <summary>    /// Checks a string against a case-sensitive acceptable-value filter.    /// </summary>    /// <param name="ValueToCheck">The string to evaluate.</param>    /// <param name="AcceptableValue">The acceptable-value filter expression.</param>    /// <returns>True if the string satisfies the filter.</returns>    internal procedure CheckIfValueIsString(ValueToCheck: Text; AcceptableValue: Text): Boolean    var        QltyCaseSensitivity: Enum "Qlty. Case Sensitivity";    begin        exit(CheckIfValueIsString(ValueToCheck, AcceptableValue, QltyCaseSensitivity::Sensitive));    end;    /// <summary>    /// Checks a string against an acceptable-value filter with specified case sensitivity.    /// </summary>    /// <param name="ValueToCheck">The string to evaluate.</param>    /// <param name="AcceptableValue">The acceptable-value filter expression.</param>    /// <param name="QltyCaseSensitivity">The case sensitivity used for comparison.</param>    /// <returns>True if the string satisfies the filter.</returns>    internal procedure CheckIfValueIsString(ValueToCheck: Text; AcceptableValue: Text; QltyCaseSensitivity: Enum "Qlty. Case Sensitivity"): Boolean    var        TempTestStringValueQltyTest: Record "Qlty. Test" temporary;    begin        if IsAnythingExceptEmptyCondition(AcceptableValue) then            exit(ValueToCheck <> '');        if QltyCaseSensitivity = QltyCaseSensitivity::Insensitive then begin            TempTestStringValueQltyTest."Allowable Values" := CopyStr(ValueToCheck.ToLower(), 1, MaxStrLen(TempTestStringValueQltyTest."Allowable Values"));            AcceptableValue := AcceptableValue.ToLower();        end else            TempTestStringValueQltyTest."Allowable Values" := CopyStr(ValueToCheck, 1, MaxStrLen(TempTestStringValueQltyTest."Allowable Values"));        TempTestStringValueQltyTest.Insert();        TempTestStringValueQltyTest.SetFilter("Allowable Values", AcceptableValue);        exit(not TempTestStringValueQltyTest.IsEmpty());    end;    /// <summary>    /// Checks whether a value equals a literal entry in a comma- or pipe-separated list.    /// </summary>    /// <param name="ValueToCheck">The value to find.</param>    /// <param name="AcceptableValue">The predefined value list.</param>    /// <param name="QltyCaseSensitivity">The case sensitivity used for comparison.</param>    /// <returns>True if the value is accepted by the list condition.</returns>    internal procedure CheckIfValueIsInPredefinedList(ValueToCheck: Text; AcceptableValue: Text; QltyCaseSensitivity: Enum "Qlty. Case Sensitivity"): Boolean    var        SingleAcceptableValue: Text;    begin        // Option and Table Lookup tests use a fixed set of predefined values. Their conditions are a        // comma or pipe separated list of literal values that may contain special filter characters such        // as parentheses, so they must be compared literally instead of being interpreted as a filter.        if IsAnythingExceptEmptyCondition(AcceptableValue) then            exit(ValueToCheck <> '');        if IsBlankOrEmptyCondition(AcceptableValue) then            exit(true);        if QltyCaseSensitivity = QltyCaseSensitivity::Insensitive then begin            ValueToCheck := ValueToCheck.ToLower();            AcceptableValue := AcceptableValue.ToLower();        end;        AcceptableValue := AcceptableValue.Replace('|', ',');        foreach SingleAcceptableValue in AcceptableValue.Split(',') do begin            SingleAcceptableValue := SingleAcceptableValue.Trim();            if SingleAcceptableValue = '' then                continue;            if ValueToCheck = SingleAcceptableValue then                exit(true);        end;        exit(false);    end;    /// <summary>    /// OnBeforeEvaluateResult gives an opportunity to change how a result is evaluated.    /// </summary>    /// <param name="QltyIResultConditConf">var Record "Qlty. Result Condition Config".</param>    /// <param name="QltyTestValueType">var Rnum "Qlty. Test Value Type".</param>    /// <param name="TestValue">var Text.</param>    /// <param name="Result">The result code supplied by a subscriber.</param>    /// <param name="IsHandled">Set to true to replace the default behavior.</param>    [IntegrationEvent(false, false)]    local procedure OnBeforeEvaluateResult(var QltyIResultConditConf: Record "Qlty. I. Result Condit. Conf."; var QltyTestValueType: Enum "Qlty. Test Value Type"; var TestValue: Text; var Result: Code[20]; var IsHandled: Boolean)    begin    end;    /// <summary>    /// OnAfterEvaluateResult gives an opportunity to run additional logic after a result has been determined by the system.    /// </summary>    /// <param name="QltyIResultConditConf">var Record "Qlty. Result Condition Config".</param>    /// <param name="QltyTestValueType">var Enum "Qlty. Test Value Type".</param>    /// <param name="TestValue">var Text.</param>    /// <param name="Result">var Code[20].</param>    /// <param name="TempHighestQltyIResultConditConf">var Record "Qlty. I. Result Condit. Conf." temporary.</param>    [IntegrationEvent(false, false)]    local procedure OnAfterEvaluateResult(var QltyIResultConditConf: Record "Qlty. I. Result Condit. Conf."; var QltyTestValueType: Enum "Qlty. Test Value Type"; var TestValue: Text; var Result: Code[20]; var TempHighestQltyIResultConditConf: Record "Qlty. I. Result Condit. Conf." temporary)    begin    end;    /// <summary>    /// Allows you to alter the behavior of validating allowable values on text.    /// </summary>    /// <param name="TestNameForError">The test identifier used in validation errors.</param>    /// <param name="TextToValidate">The value to validate and normalize.</param>    /// <param name="AllowableValues">The allowable values expression.</param>    /// <param name="QltyTestValueType">The data type used to interpret the value.</param>    /// <param name="TempBufferQltyTestLookupValue">The allowable lookup values.</param>    /// <param name="QltyCaseSensitivity">The case sensitivity used for matching.</param>    /// <param name="IsHandled">Set to true to replace the default validation.</param>    [IntegrationEvent(false, false)]    local procedure OnBeforeValidateAllowableValuesOnText(var TestNameForError: Text; var TextToValidate: Text[250]; var AllowableValues: Text; var QltyTestValueType: Enum "Qlty. Test Value Type"; var TempBufferQltyTestLookupValue: Record "Qlty. Test Lookup Value" temporary; var QltyCaseSensitivity: Enum "Qlty. Case Sensitivity"; var IsHandled: Boolean)    begin    end;    /// <summary>    /// Provides the opportunity to extend and add additional validation after the allowable values has occurred.    /// </summary>    /// <param name="TestNameForError">The test identifier used in validation errors.</param>    /// <param name="TextToValidate">The validated and normalized value.</param>    /// <param name="AllowableValues">The allowable values expression.</param>    /// <param name="QltyTestValueType">The data type used to interpret the value.</param>    /// <param name="TempBufferQltyTestLookupValue">The allowable lookup values.</param>    /// <param name="QltyCaseSensitivity">The case sensitivity used for matching.</param>    [IntegrationEvent(false, false)]    local procedure OnAfterValidateAllowableValuesOnText(var TestNameForError: Text; var TextToValidate: Text[250]; var AllowableValues: Text; var QltyTestValueType: Enum "Qlty. Test Value Type"; var TempBufferQltyTestLookupValue: Record "Qlty. Test Lookup Value" temporary; var QltyCaseSensitivity: Enum "Qlty. Case Sensitivity")    begin    end;}