Report 20412 Qlty. Schedule Inspection
src/Apps/W1/Quality Management/app/src/Configuration/GenerationRule/JobQueue/QltyScheduleInspection.Report.al174 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.GenerationRule.JobQueue;using Microsoft.QualityManagement.Configuration.GenerationRule;using Microsoft.QualityManagement.Configuration.SourceConfiguration;using Microsoft.QualityManagement.Document;using Microsoft.QualityManagement.Setup;report 20412 "Qlty. Schedule Inspection"{ Caption = 'Quality Management - Schedule Inspection'; AdditionalSearchTerms = 'Periodic inspections'; ToolTip = 'Run this report to bulk create inspections based on generation rules for the selected template, or schedule it in the job queue for periodic inspection creation.'; ProcessingOnly = true; AccessByPermission = tabledata "Qlty. Inspection Gen. Rule" = R; ApplicationArea = QualityManagement; UsageCategory = Tasks; AllowScheduling = true; dataset { dataitem(CurrentInspectionGenerationRule; "Qlty. Inspection Gen. Rule") { RequestFilterFields = "Schedule Group", "Template Code", Description; DataItemTableView = where("Activation Trigger" = filter(<> Disabled)); trigger OnAfterGetRecord() begin CreateInspectionsThatMatchRule(CurrentInspectionGenerationRule); end; trigger OnPreDataItem() begin end; } } requestpage { layout { area(Content) { group(Warning) { Caption = 'Warning'; Visible = ShowWarningIfCreateInspection; InstructionalText = 'On your Quality Management Setup page you have the Inspection Creation Option set to a setting that will cause inspections to be created whenever this report is run even if there are already inspections for that item and item tracking. Make sure this is compatible with the scenario you are solving.'; field(ChooseOpenQualityManagementSetup; 'Click here to open the Quality Management Setup page.') { ShowCaption = false; ApplicationArea = QualityManagement; trigger OnDrillDown() begin QltyManagementSetup.Get(); Page.RunModal(Page::"Qlty. Management Setup", QltyManagementSetup, QltyManagementSetup.FieldNo("Inspection Creation Option")); end; } } } } } var QltyManagementSetup: Record "Qlty. Management Setup"; QltyInspectionCreate: Codeunit "Qlty. Inspection - Create"; ShowWarningIfCreateInspection: Boolean; NewlyCreatedQltyInspectionIds, AllResolvedQltyInspectionIds : List of [Code[20]]; ZeroInspectionsCreatedOrMatchedMsg: Label 'No inspections were created or existing inspections matched.'; SomeInspectionsCreatedQst: Label '%1 inspections were created. Do you want to see them?', Comment = '%1=the count of inspections that were newly created.'; SomeInspectionsMatchedQst: Label 'No new inspections were created, but %1 existing inspections matched. Do you want to see them?', Comment = '%1=the count of existing inspections that were matched (reused).'; SomeInspectionsCreatedOrMatchedQst: Label '%1 inspections were created and %2 existing inspections matched. Do you want to see all of them?', Comment = '%1=the count of newly created inspections, %2=the count of existing inspections that were matched (reused).'; NoSourceConfigForScheduleErr: Label 'Cannot schedule inspections because no enabled source configuration with a table filter exists for source table %1. Navigate to the Quality Inspection Source Configuration page and ensure at least one enabled configuration exists for this table with a From Table Filter defined.', Comment = '%1=the source table number'; trigger OnInitReport() begin QltyManagementSetup.Get(); if QltyManagementSetup."Inspection Creation Option" in [QltyManagementSetup."Inspection Creation Option"::"Always create new inspection", QltyManagementSetup."Inspection Creation Option"::"Always create re-inspection"] then ShowWarningIfCreateInspection := true; end; trigger OnPreReport() begin Clear(QltyInspectionCreate); Clear(NewlyCreatedQltyInspectionIds); Clear(AllResolvedQltyInspectionIds); end; trigger OnPostReport() var NewlyCreatedCount, ExistingMatchedCount : Integer; ShouldDisplay: Boolean; begin if not GuiAllowed() then exit; if AllResolvedQltyInspectionIds.Count() = 0 then begin Message(ZeroInspectionsCreatedOrMatchedMsg); exit; end; NewlyCreatedCount := NewlyCreatedQltyInspectionIds.Count(); ExistingMatchedCount := AllResolvedQltyInspectionIds.Count() - NewlyCreatedCount; if ExistingMatchedCount < 0 then ExistingMatchedCount := 0; case true of (NewlyCreatedCount > 0) and (ExistingMatchedCount > 0): ShouldDisplay := Confirm(StrSubstNo(SomeInspectionsCreatedOrMatchedQst, NewlyCreatedCount, ExistingMatchedCount), true); NewlyCreatedCount > 0: ShouldDisplay := Confirm(StrSubstNo(SomeInspectionsCreatedQst, NewlyCreatedCount), true); else ShouldDisplay := Confirm(StrSubstNo(SomeInspectionsMatchedQst, ExistingMatchedCount), true); end; if ShouldDisplay then QltyInspectionCreate.DisplayInspectionsIfConfigured(true, AllResolvedQltyInspectionIds); end; /// <summary> /// Creates or matches inspections for records selected by an enabled, schedulable generation rule. /// </summary> /// <param name="QltyInspectionGenRule">The generation rule that selects the source records and inspection template.</param> procedure CreateInspectionsThatMatchRule(QltyInspectionGenRule: Record "Qlty. Inspection Gen. Rule") var QltyJobQueueManagement: Codeunit "Qlty. Job Queue Management"; begin if QltyInspectionGenRule."Activation Trigger" = QltyInspectionGenRule."Activation Trigger"::Disabled then exit; QltyJobQueueManagement.CheckIfGenerationRuleCanBeScheduled(QltyInspectionGenRule); QltyInspectionGenRule.SetRecFilter(); if QltyInspectionGenRule."Schedule Group" <> '' then QltyInspectionGenRule.SetRange("Schedule Group", QltyInspectionGenRule."Schedule Group"); QltyInspectionGenRule.SetRange("Template Code", QltyInspectionGenRule."Template Code"); CreateInspectionsPerSourceConfigFilter(QltyInspectionGenRule); end; /// <summary> /// Creates inspections for source records that satisfy each enabled source configuration filter for the generation rule. /// </summary> /// <param name="QltyInspectionGenRule">The generation rule whose source table and condition filter select records.</param> local procedure CreateInspectionsPerSourceConfigFilter(var QltyInspectionGenRule: Record "Qlty. Inspection Gen. Rule") var QltyInspectSourceConfig: Record "Qlty. Inspect. Source Config."; SourceRecordRef: RecordRef; begin QltyInspectSourceConfig.SetRange("From Table No.", QltyInspectionGenRule."Source Table No."); QltyInspectSourceConfig.SetRange("To Type", QltyInspectSourceConfig."To Type"::Inspection); QltyInspectSourceConfig.SetRange(Enabled, true); QltyInspectSourceConfig.SetFilter("From Table Filter", '<>%1', ''); if not QltyInspectSourceConfig.FindSet() then Error(NoSourceConfigForScheduleErr, QltyInspectionGenRule."Source Table No."); repeat Clear(SourceRecordRef); SourceRecordRef.Open(QltyInspectionGenRule."Source Table No."); if QltyInspectionGenRule."Condition Filter" <> '' then SourceRecordRef.SetView(QltyInspectionGenRule."Condition Filter"); SourceRecordRef.FilterGroup(20); SourceRecordRef.SetView(QltyInspectSourceConfig."From Table Filter"); SourceRecordRef.FilterGroup(0); if SourceRecordRef.FindSet() then QltyInspectionCreate.CreateMultipleInspectionsWithoutDisplaying(SourceRecordRef, GuiAllowed(), QltyInspectionGenRule, NewlyCreatedQltyInspectionIds, AllResolvedQltyInspectionIds); until QltyInspectSourceConfig.Next() = 0; end;}