From d57ff2f12c1442e58dc2d876244092b8436ccde1 Mon Sep 17 00:00:00 2001 From: Dusan Jakovljevic <134404137+JakovljevicDusan@users.noreply.github.com> Date: Mon, 25 May 2026 20:18:10 +0200 Subject: [PATCH 1/3] Enhance error messaging for test value type changes and improve validation logic --- .../Template/Test/QltyTest.Table.al | 55 ++++++++++++------- .../test/src/QltyTestsMoreTests.Codeunit.al | 6 +- .../test/src/QltyTestsTestTable.Codeunit.al | 2 +- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/Apps/W1/Quality Management/app/src/Configuration/Template/Test/QltyTest.Table.al b/src/Apps/W1/Quality Management/app/src/Configuration/Template/Test/QltyTest.Table.al index 9f4cbf3006..6519f5e7e2 100644 --- a/src/Apps/W1/Quality Management/app/src/Configuration/Template/Test/QltyTest.Table.al +++ b/src/Apps/W1/Quality Management/app/src/Configuration/Template/Test/QltyTest.Table.al @@ -47,7 +47,7 @@ table 20401 "Qlty. Test" trigger OnValidate() begin - HandleOnValidateTestValueType(true); + HandleOnValidateTestValueType(); end; } field(5; "Allowable Values"; Text[500]) @@ -203,11 +203,12 @@ table 20401 "Qlty. Test" ReviewResultsErr: Label 'Advanced configuration required. Please review the result configurations for test "%1", for result "%2".', Comment = '%1=the test, %2=the result'; OnlyFieldExpressionErr: Label 'The Expression Formula can only be used with fields that are a type of Expression'; BooleanChoiceListLbl: Label 'No,Yes'; - ExistingInspectionErr: Label 'The test %1 exists on %2 inspections (such as %3 with template %4). The test can not be deleted if it is being used on a Quality Inspection.', Comment = '%1=the test, %2=count of inspections, %3=one example inspection, %4=example template.'; + ExistingInspectionErr: Label 'The test %1 exists on %2 inspections (such as %3 with template %4). The test cannot be deleted if it is being used on a quality inspection.', Comment = '%1=the test, %2=count of inspections, %3=one example inspection, %4=example template.'; DeleteQst: Label 'The test %3 exists on %1 Quality Inspection Template(s) (such as template %2) that will be deleted. Do you wish to proceed?', Comment = '%1 = the lines, %2= the Template Code, %3=the test'; - DeleteErr: Label 'The test %3 exists on %1 Quality Inspection Template(s) (such as template %2) and can not be deleted until it is no longer used on templates.', Comment = '%1 = the lines, %2= the Template Code, %3=the test'; - TestValueTypeErrTitleMsg: Label 'Test Value Type cannot be changed for a test that has been used in inspections.'; - TestValueTypeErrInfoMsg: Label '%1Consider replacing this test in the template with a new one, or deleting existing inspections (if allowed). The test was last used on inspection %2.', Comment = '%1 = Error Title, %2 = Quality Inspection No.'; + DeleteErr: Label 'The test %3 exists on %1 Quality Inspection Template(s) (such as template %2) and cannot be deleted until it is no longer used on templates.', Comment = '%1 = the lines, %2= the Template Code, %3=the test'; + TestValueTypeChangeErrTitleMsg: Label 'Cannot change the test value type for a test that is already in use on inspections.'; + TestValueTypeChangeErrInfoMsg: Label 'Consider replacing this test in the template with a new one, or deleting existing inspections (if allowed). The test was last used on Inspection %1, Re-inspection %2.', Comment = '%1 = Quality Inspection No., %2 = Re-inspection No.'; + ShowInspectionActionLbl: Label 'Show Inspection %1 %2', Comment = '%1=Inspection No., %2=Re-inspection No.'; /// /// Set a specific result for the test. If AllowError is set to true it will error @@ -533,20 +534,11 @@ table 20401 "Qlty. Test" end; end; - internal procedure HandleOnValidateTestValueType(AllowActionableError: Boolean) + internal procedure HandleOnValidateTestValueType() var - QltyInspectionLine: Record "Qlty. Inspection Line"; - QltyInspectionHeader: Record "Qlty. Inspection Header"; QltyResultConditionMgmt: Codeunit "Qlty. Result Condition Mgmt."; begin - QltyInspectionLine.SetRange("Test Code", Rec.Code); - if QltyInspectionLine.FindLast() then begin - if QltyInspectionHeader.Get(QltyInspectionLine."Inspection No.", QltyInspectionLine."Re-inspection No.") then; - if AllowActionableError then - Error(TestValueTypeErrInfoMsg, TestValueTypeErrTitleMsg, QltyInspectionHeader."No.") - else - Error(TestValueTypeErrInfoMsg, TestValueTypeErrTitleMsg, QltyInspectionHeader."No."); - end; + CheckTestNotUsedInInspections(); if Rec."Test Value Type" <> xRec."Test Value Type" then begin Rec."Allowable Values" := ''; @@ -561,6 +553,31 @@ table 20401 "Qlty. Test" QltyResultConditionMgmt.CopyResultConditionsFromDefaultToTest(Rec.Code, Rec."Test Value Type"); end; + local procedure CheckTestNotUsedInInspections() + var + QltyInspectionLine: Record "Qlty. Inspection Line"; + QltyInspectionHeader: Record "Qlty. Inspection Header"; + begin + QltyInspectionLine.SetRange("Test Code", Rec.Code); + if QltyInspectionLine.FindLast() then begin + QltyInspectionHeader.Get(QltyInspectionLine."Inspection No.", QltyInspectionLine."Re-inspection No."); + + ThrowTestUsedInInspectionsError(QltyInspectionHeader); + end; + end; + + local procedure ThrowTestUsedInInspectionsError(QltyInspectionHeader: Record "Qlty. Inspection Header") + var + ErrorInfo: ErrorInfo; + begin + ErrorInfo.Title := TestValueTypeChangeErrTitleMsg; + ErrorInfo.Message := StrSubstNo(TestValueTypeChangeErrInfoMsg, QltyInspectionHeader."No.", QltyInspectionHeader."Re-inspection No."); + ErrorInfo.PageNo := Page::"Qlty. Inspection"; + ErrorInfo.RecordId := QltyInspectionHeader.RecordId(); + ErrorInfo.AddNavigationAction(StrSubstNo(ShowInspectionActionLbl, QltyInspectionHeader."No.", QltyInspectionHeader."Re-inspection No.")); + Error(ErrorInfo); + end; + procedure AssistEditExpressionFormula() var QltyInspectionTemplateEdit: Page "Qlty. Inspection Template Edit"; @@ -615,9 +632,9 @@ table 20401 "Qlty. Test" if IsHandled then exit; - IsNumeric := Rec."Test Value Type" in [Rec."Test Value Type"::"Value Type Decimal", - Rec."Test Value Type"::"Value Type Integer" - ]; + IsNumeric := Rec."Test Value Type" in + [Rec."Test Value Type"::"Value Type Decimal", + Rec."Test Value Type"::"Value Type Integer"]; end; /// diff --git a/src/Apps/W1/Quality Management/test/src/QltyTestsMoreTests.Codeunit.al b/src/Apps/W1/Quality Management/test/src/QltyTestsMoreTests.Codeunit.al index 975c3052d6..8c00c320dd 100644 --- a/src/Apps/W1/Quality Management/test/src/QltyTestsMoreTests.Codeunit.al +++ b/src/Apps/W1/Quality Management/test/src/QltyTestsMoreTests.Codeunit.al @@ -60,7 +60,7 @@ codeunit 139965 "Qlty. Tests - More Tests" ConditionProductionFilterTok: Label 'WHERE(Order Type=FILTER(Production))', Locked = true; DefaultScheduleGroupTok: Label 'QM', Locked = true; ExpressionFormulaTok: Label '[No.]'; - TestTypeErrInfoMsg: Label '%1Consider replacing this test in the template with a new one, or deleting existing inspections (if allowed). The test was last used on inspection %2.', Comment = '%1 = Error Title, %2 = Quality Inspection No.'; + TestValueTypeChangeErrInfoMsg: Label 'Consider replacing this test in the template with a new one, or deleting existing inspections (if allowed). The test was last used on Inspection %1, Re-inspection %2.', Comment = '%1 = Quality Inspection No., %2 = Re-inspection No.'; OnlyFieldExpressionErr: Label 'The Expression Formula can only be used with fields that are a type of Expression'; VendorFilterCountryTok: Label 'WHERE(Country/Region Code=FILTER(CA))', Locked = true; VendorFilterNoTok: Label 'WHERE(No.=FILTER(%1))', Comment = '%1 = Vendor No.', Locked = true; @@ -229,7 +229,7 @@ codeunit 139965 "Qlty. Tests - More Tests" end; [Test] - procedure TestTable_ValidateTestValueType_ShouldError() + procedure TestTable_ValidateTestValueTypeChange_ShouldError() var ToLoadQltyTest: Record "Qlty. Test"; QltyInspectionHeader: Record "Qlty. Inspection Header"; @@ -252,7 +252,7 @@ codeunit 139965 "Qlty. Tests - More Tests" asserterror ToLoadQltyTest.Validate("Test Value Type", ToLoadQltyTest."Test Value Type"::"Value Type Boolean"); // [THEN] An error is raised indicating the test value type cannot be changed because it's used in inspection - LibraryAssert.ExpectedError(StrSubstNo(TestTypeErrInfoMsg, '', QltyInspectionHeader."No.")); + LibraryAssert.ExpectedError(StrSubstNo(TestValueTypeChangeErrInfoMsg, QltyInspectionHeader."No.", QltyInspectionHeader."Re-inspection No.")); end; [Test] diff --git a/src/Apps/W1/Quality Management/test/src/QltyTestsTestTable.Codeunit.al b/src/Apps/W1/Quality Management/test/src/QltyTestsTestTable.Codeunit.al index 31eaaa7855..854637a53a 100644 --- a/src/Apps/W1/Quality Management/test/src/QltyTestsTestTable.Codeunit.al +++ b/src/Apps/W1/Quality Management/test/src/QltyTestsTestTable.Codeunit.al @@ -65,7 +65,7 @@ codeunit 139967 "Qlty. Tests - Test Table" OptionsTok: Label 'Option1,Option2,Option3'; Option1Tok: Label 'Option1'; NoTok: Label 'No'; - ExistingInspectiontErr: Label 'The test %1 exists on %2 inspections (such as %3 with template %4). The test can not be deleted if it is being used on a Quality Inspection.', Comment = '%1=the test, %2=count of inspections, %3=one example inspection, %4=example template.'; + ExistingInspectiontErr: Label 'The test %1 exists on %2 inspections (such as %3 with template %4). The test cannot be deleted if it is being used on a quality inspection.', Comment = '%1=the test, %2=count of inspections, %3=one example inspection, %4=example template.'; DescriptionTxt: Label 'Specific Gravity'; SuggestedCodeTxtTestValueTxt: Label 'SPECIFICGRAVITY'; Description2Txt: Label '><{}.@!`~''"|\/?&*()-_$#-=,%%:ELECTRICAL CONDUCTIVITY'; From c1f81ae09fa7417eba149e4ac660e9f65cc8d1ca Mon Sep 17 00:00:00 2001 From: Dusan Jakovljevic <134404137+JakovljevicDusan@users.noreply.github.com> Date: Mon, 25 May 2026 21:01:27 +0200 Subject: [PATCH 2/3] Address code review suggestions --- .../app/src/Configuration/Template/Test/QltyTest.Table.al | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Apps/W1/Quality Management/app/src/Configuration/Template/Test/QltyTest.Table.al b/src/Apps/W1/Quality Management/app/src/Configuration/Template/Test/QltyTest.Table.al index 6519f5e7e2..fac1b690a5 100644 --- a/src/Apps/W1/Quality Management/app/src/Configuration/Template/Test/QltyTest.Table.al +++ b/src/Apps/W1/Quality Management/app/src/Configuration/Template/Test/QltyTest.Table.al @@ -209,6 +209,7 @@ table 20401 "Qlty. Test" TestValueTypeChangeErrTitleMsg: Label 'Cannot change the test value type for a test that is already in use on inspections.'; TestValueTypeChangeErrInfoMsg: Label 'Consider replacing this test in the template with a new one, or deleting existing inspections (if allowed). The test was last used on Inspection %1, Re-inspection %2.', Comment = '%1 = Quality Inspection No., %2 = Re-inspection No.'; ShowInspectionActionLbl: Label 'Show Inspection %1 %2', Comment = '%1=Inspection No., %2=Re-inspection No.'; + InspectionLineExistsButHeaderMissingErr: Label 'The test %1 exists on inspection line with Inspection No. %2, Re-inspection %3, but the inspection header record is missing. This indicates a data integrity issue.', Comment = '%1=Test Code, %2=Inspection No., %3=Re-inspection No.'; /// /// Set a specific result for the test. If AllowError is set to true it will error @@ -380,6 +381,7 @@ table 20401 "Qlty. Test" QltyInspectionLine.SetRange("Test Code", Rec.Code); LineCount := QltyInspectionLine.Count(); if LineCount > 0 then begin + QltyInspectionLine.SetLoadFields("Test Code", "Template Code"); QltyInspectionLine.FindFirst(); Error(ExistingInspectionErr, QltyInspectionLine."Test Code", @@ -534,7 +536,7 @@ table 20401 "Qlty. Test" end; end; - internal procedure HandleOnValidateTestValueType() + local procedure HandleOnValidateTestValueType() var QltyResultConditionMgmt: Codeunit "Qlty. Result Condition Mgmt."; begin @@ -558,9 +560,11 @@ table 20401 "Qlty. Test" QltyInspectionLine: Record "Qlty. Inspection Line"; QltyInspectionHeader: Record "Qlty. Inspection Header"; begin + QltyInspectionLine.SetLoadFields("Inspection No.", "Re-inspection No."); QltyInspectionLine.SetRange("Test Code", Rec.Code); if QltyInspectionLine.FindLast() then begin - QltyInspectionHeader.Get(QltyInspectionLine."Inspection No.", QltyInspectionLine."Re-inspection No."); + if not QltyInspectionHeader.Get(QltyInspectionLine."Inspection No.", QltyInspectionLine."Re-inspection No.") then + Error(InspectionLineExistsButHeaderMissingErr, Rec.Code, QltyInspectionLine."Inspection No.", QltyInspectionLine."Re-inspection No."); ThrowTestUsedInInspectionsError(QltyInspectionHeader); end; From 459b81f3497889fb829f126516526a77013bcf81 Mon Sep 17 00:00:00 2001 From: Dusan Jakovljevic <134404137+JakovljevicDusan@users.noreply.github.com> Date: Mon, 25 May 2026 21:24:54 +0200 Subject: [PATCH 3/3] Remove obsolete comments --- .../Quality Management/test/src/QltyTestsMoreTests.Codeunit.al | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Apps/W1/Quality Management/test/src/QltyTestsMoreTests.Codeunit.al b/src/Apps/W1/Quality Management/test/src/QltyTestsMoreTests.Codeunit.al index 8c00c320dd..70e318c1ef 100644 --- a/src/Apps/W1/Quality Management/test/src/QltyTestsMoreTests.Codeunit.al +++ b/src/Apps/W1/Quality Management/test/src/QltyTestsMoreTests.Codeunit.al @@ -2113,8 +2113,6 @@ codeunit 139965 "Qlty. Tests - More Tests" LibraryAssert.ExpectedError(CanOnlyBeSetWhenToTypeIsInspectionErr); end; - // Test disabled due to inconsistent behavior across environments - // Bug 613059 to address the test stability issue [Test] procedure ApplicationAreaMgmt_IsQualityManagementApplicationAreaEnabled() var