Skip to content

[Vendor] [Quality Management] Agentic review - Error Handling: QltyInspectionLine - No Pre-Condition Validation in OnModify Trigger #6437

@PredragMaricic

Description

@PredragMaricic

Describe the issue

ISSUE 6.8: No Pre-Condition Validation in OnModify Trigger

Severity: HIGH
Category: Validation & Data Integrity
Files: src/Document/QltyInspectionTestLine.Table.al

Problem:
The OnModify trigger attempts numeric conversion but doesn't validate the test line state or status before modification.

Code Location (Lines 218-226):

trigger OnModify()
begin
    if not Rec.IsTemporary() then
        TestStatusOpen();  // Only checks if test is open

    Rec."Numeric Value" := 0;
    if Evaluate(Rec."Numeric Value", Rec."Test Value") then;  // DEFECT: Ignored result
end;

Issues:

  1. Silent Failure: Evaluate result ignored - "Numeric Value" stays 0 if conversion fails
  2. No Field Validation: Doesn't check if "Test Value" field type is numeric
  3. No Error Message: User has no idea conversion failed

Scenarios:

// SCENARIO 1: Text field treated as numeric
Field Type = "Text"
Test Value = "Some text"
OnModify: Evaluate fails silently
Numeric Value = 0 (wrong - should be null or error)

// SCENARIO 2: Invalid numeric format
Field Type = "Integer"
Test Value = "12.5.7"  // Invalid
OnModify: Evaluate fails silently
Numeric Value = 0 (wrong - should show error)

// SCENARIO 3: Overflow
Field Type = "Integer"
Test Value = "999999999999999"  // Exceeds integer max
OnModify: Evaluate fails silently
Numeric Value = 0 (wrong - data loss)

Recommended Fix:

trigger OnModify()
var
    ConversionSuccess: Boolean;
begin
    if not Rec.IsTemporary() then
        TestStatusOpen();

    // Only attempt numeric conversion for numeric field types
    Rec.CalcFields("Field Type");
    if Rec."Field Type" in [Rec."Field Type"::"Field Type Decimal", Rec."Field Type"::"Field Type Integer"] then begin
        Rec."Numeric Value" := 0;
       
        if Rec."Test Value" <> '' then begin
            ClearLastError();
            ConversionSuccess := Evaluate(Rec."Numeric Value", Rec."Test Value");
           
            if not ConversionSuccess then
                Error(InvalidNumericValueErr, Rec."Test Value", Rec."Field Code", Rec."Field Type");
        end;
    end else
        Rec."Numeric Value" := 0;  // Clear for non-numeric types
end;

var
    InvalidNumericValueErr: Label 'The value "%1" is not a valid %3 for field "%2". Please enter a valid numeric value.', Comment = '%1=entered value, %2=field code, %3=field type';

Expected behavior

Steps to reproduce

Additional context

I will provide a fix for a bug

  • I will provide a fix for a bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApprovedThe issue is approvedSCMGitHub request for SCM area

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions