diff --git a/src/Apps/W1/Quality Management/app/src/Configuration/Grade/QltyGradeConditionMgmt.Codeunit.al b/src/Apps/W1/Quality Management/app/src/Configuration/Grade/QltyGradeConditionMgmt.Codeunit.al
index 32fa5a0da2..1bde64e1c4 100644
--- a/src/Apps/W1/Quality Management/app/src/Configuration/Grade/QltyGradeConditionMgmt.Codeunit.al
+++ b/src/Apps/W1/Quality Management/app/src/Configuration/Grade/QltyGradeConditionMgmt.Codeunit.al
@@ -244,6 +244,28 @@ codeunit 20409 "Qlty. Grade Condition Mgmt."
until FromTemplateQltyIGradeConditionConf.Next() = 0;
end;
+ ///
+ /// This will copy any grade configurations configured to automatically copy to all existing templates.
+ /// This leverages how CopyGradeConditionsFromFieldToTemplateLine will already update fields via CopyGradeConditionsFromDefaultToField
+ /// when a specific grade is supplied.
+ ///
+ procedure CopyGradeConditionsFromDefaultToAllTemplates()
+ var
+ QltInspectionGrade: Record "Qlty. Inspection Grade";
+ QltyInspectionTemplateLine: Record "Qlty. Inspection Template Line";
+ begin
+ QltInspectionGrade.SetRange("Copy Behavior", QltInspectionGrade."Copy Behavior"::"Automatically copy the grade");
+ if QltInspectionGrade.FindSet() then
+ repeat
+ if QltyInspectionTemplateLine.FindSet(false) then
+ repeat
+ // We're using 'false' here because we do not want to replace the conditions, only add new ones.
+ // We do not want to remove grades that were previously added to templates.
+ CopyGradeConditionsFromFieldToTemplateLine(QltyInspectionTemplateLine."Template Code", QltyInspectionTemplateLine."Line No.", QltInspectionGrade.Code, false);
+ until (QltyInspectionTemplateLine.Next() = 0);
+ until (QltInspectionGrade.Next() = 0);
+ end;
+
///
/// Copies the default grade conditions into the specified field.
///
diff --git a/src/Apps/W1/Quality Management/app/src/Configuration/Grade/QltyInspectionGradeList.Page.al b/src/Apps/W1/Quality Management/app/src/Configuration/Grade/QltyInspectionGradeList.Page.al
index c3471d5f27..8aeaf8d8fe 100644
--- a/src/Apps/W1/Quality Management/app/src/Configuration/Grade/QltyInspectionGradeList.Page.al
+++ b/src/Apps/W1/Quality Management/app/src/Configuration/Grade/QltyInspectionGradeList.Page.al
@@ -162,6 +162,26 @@ page 20416 "Qlty. Inspection Grade List"
}
}
+ actions
+ {
+ area(Processing)
+ {
+ action(CopyGradesToAllTemplates)
+ {
+ ApplicationArea = QualityManagement;
+ Caption = 'Copy Grades to Existing Templates';
+ ToolTip = 'Use this to add newly created grades configured to Automatically Copy on to existing fields and existing templates.';
+ Image = Copy;
+ trigger OnAction()
+ var
+ QltyGradeConditionMgmt: Codeunit "Qlty. Grade Condition Mgmt.";
+ begin
+ QltyGradeConditionMgmt.CopyGradeConditionsFromDefaultToAllTemplates();
+ end;
+ }
+ }
+ }
+
var
MustChangePriorityErr: Label 'Evaluation Sequence must be unique, you cannot have two grades with the same evaluation sequence. Grade [%1/%2] already has the same evaluation sequence.', Comment = '%1=The grade code, %2=the grade condition';
diff --git a/src/Apps/W1/Quality Management/test/src/QltyTestGradeCondition.Codeunit.al b/src/Apps/W1/Quality Management/test/src/QltyTestGradeCondition.Codeunit.al
index 170642dff5..f97c82e045 100644
--- a/src/Apps/W1/Quality Management/test/src/QltyTestGradeCondition.Codeunit.al
+++ b/src/Apps/W1/Quality Management/test/src/QltyTestGradeCondition.Codeunit.al
@@ -514,6 +514,75 @@ codeunit 139956 "Qlty. Test Grade Condition"
LibraryAssert.AreEqual(ToLoadQltyIGradeConditionConf.Condition, ToLoadSecondQltyIGradeConditionConf.Condition, 'The condition should match the copied template line.');
end;
+ [Test]
+ procedure CopyGradeConditionsFromDefaultToAllTemplates_WithNewGradeConfiguredToCopy()
+ var
+ QltyInspectionGrade: Record "Qlty. Inspection Grade";
+ ToLoadQltyField: Record "Qlty. Field";
+ ConfigurationToLoadQltyInspectionTemplateHdr: Record "Qlty. Inspection Template Hdr.";
+ ConfigurationToLoadSecondQltyInspectionTemplateHdr: Record "Qlty. Inspection Template Hdr.";
+ ConfigurationToLoadQltyInspectionTemplateLine: Record "Qlty. Inspection Template Line";
+ ConfigurationToLoadSecondQltyInspectionTemplateLine: Record "Qlty. Inspection Template Line";
+ ToLoadQltyIGradeConditionConf: Record "Qlty. I. Grade Condition Conf.";
+ ToLoadSecondQltyIGradeConditionConf: Record "Qlty. I. Grade Condition Conf.";
+ FieldCode: Text;
+ BeforeNewGradeCountConditions: Integer;
+ begin
+ // [SCENARIO] Supports issue 5503, allows a scenario of adding a new grade with 'automatically copy' configured after existing grades are and adds those conditions.
+
+ Initialize();
+
+ // [GIVEN] Quality Management setup is initialized
+ QltyTestsUtility.EnsureSetup();
+
+ // [GIVEN] A first quality inspection template is created with a custom grade condition
+ QltyTestsUtility.CreateTemplate(ConfigurationToLoadQltyInspectionTemplateHdr, 0);
+ Clear(ToLoadQltyField);
+ ToLoadQltyField.Init();
+ QltyTestsUtility.GenerateRandomCharacters(MaxStrLen(ToLoadQltyField.Code), FieldCode);
+ ToLoadQltyField.Code := CopyStr(FieldCode, 1, MaxStrLen(ToLoadQltyField.Code));
+ ToLoadQltyField.Validate("Field Type", ToLoadQltyField."Field Type"::"Field Type Decimal");
+ ToLoadQltyField.Insert();
+
+ ConfigurationToLoadQltyInspectionTemplateLine.Init();
+ ConfigurationToLoadQltyInspectionTemplateLine."Template Code" := ConfigurationToLoadQltyInspectionTemplateHdr.Code;
+ ConfigurationToLoadQltyInspectionTemplateLine.InitLineNoIfNeeded();
+ ConfigurationToLoadQltyInspectionTemplateLine.Validate("Field Code", ToLoadQltyField.Code);
+ ConfigurationToLoadQltyInspectionTemplateLine.Insert();
+ ConfigurationToLoadQltyInspectionTemplateLine.EnsureGrades(false);
+ ToLoadQltyIGradeConditionConf.Get(ToLoadQltyIGradeConditionConf."Condition Type"::Template, ConfigurationToLoadQltyInspectionTemplateHdr.Code, 0, 10000, ToLoadQltyField.Code, DefaultGrade2PassCodeTok);
+ ToLoadQltyIGradeConditionConf.Condition := InitialConditionTok;
+ ToLoadQltyIGradeConditionConf.Modify();
+
+ // This is not testing the scenario, this is just validating the preconditions.
+ QltyInspectionGrade.SetRange("Copy Behavior", QltyInspectionGrade."Copy Behavior"::"Automatically copy the grade");
+ LibraryAssert.IsTrue(QltyInspectionGrade.Count() > 0, 'Validating preconditions. There must be n>0 grades that copy for this test to be valid.');
+ ToLoadQltyIGradeConditionConf.SetRecFilter();
+ ToLoadQltyIGradeConditionConf.SetRange("Grade Code");
+ BeforeNewGradeCountConditions := QltyInspectionGrade.Count();
+ LibraryAssert.AreEqual(BeforeNewGradeCountConditions, ToLoadQltyIGradeConditionConf.Count(), 'Validating preconditions. Grade.Count(where copy is on) should equal the grade count for a given template line.');
+
+ // [GIVEN] Another net new grade with a copy behavior.
+ QltyInspectionGrade.Init();
+ QltyInspectionGrade.Code := 'AUTOMATEDTEST';
+ QltyInspectionGrade.Description := 'Automated test.';
+ QltyInspectionGrade."Copy Behavior" := QltyInspectionGrade."Copy Behavior"::"Automatically copy the grade";
+ QltyInspectionGrade.Insert(true);
+
+ // [WHEN] We ask the system to copy the new grades to all templates
+ CondManagementQltyGradeConditionMgmt.CopyGradeConditionsFromDefaultToAllTemplates();
+
+ // [THEN] The grade condition count should now be one higher.
+ QltyInspectionGrade.SetRange("Copy Behavior", QltyInspectionGrade."Copy Behavior"::"Automatically copy the grade");
+ LibraryAssert.AreEqual(BeforeNewGradeCountConditions + 1, ToLoadQltyIGradeConditionConf.Count(), 'The grade conditions should have increased by one.');
+
+ // clean up the artifacts
+ ToLoadQltyIGradeConditionConf.Reset();
+ ToLoadQltyIGradeConditionConf.SetRange("Grade Code", QltyInspectionGrade.Code);
+ ToLoadQltyIGradeConditionConf.DeleteAll(false);
+ QltyInspectionGrade.Delete(); // remove the grade.
+ end;
+
[Test]
procedure CopyGradeConditionsFromTemplateLineToTest_NoExistingConfigLine()
var