From 458d48ef74a8859b4d64308556ebbcdd5036b5c1 Mon Sep 17 00:00:00 2001 From: Niklas Plakolb Date: Fri, 4 Oct 2024 08:13:23 +0200 Subject: [PATCH] added: status sync --- .../FSArchivedServiceOrdersJob.Codeunit.al | 7 +++ .../FSIntTableSubscriber.Codeunit.al | 45 +++++++++++++++++++ .../src/Codeunits/FSSetupDefaults.Codeunit.al | 14 ++++++ 3 files changed, 66 insertions(+) diff --git a/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSArchivedServiceOrdersJob.Codeunit.al b/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSArchivedServiceOrdersJob.Codeunit.al index 8011ade641..4aa5a63401 100644 --- a/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSArchivedServiceOrdersJob.Codeunit.al +++ b/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSArchivedServiceOrdersJob.Codeunit.al @@ -65,6 +65,7 @@ codeunit 6617 "FS Archived Service Orders Job" local procedure UpdateFromServiceHeader(var FSWorkOrder: Record "FS Work Order") begin ResetFSWorkOrderLineFromServiceOrderLine(FSWorkOrder); + MarkPosted(FSWorkOrder); end; local procedure ResetFSWorkOrderLineFromServiceOrderLine(var FSWorkOrder: Record "FS Work Order") @@ -91,6 +92,12 @@ codeunit 6617 "FS Archived Service Orders Job" until FSWorkOrderService.Next() = 0; end; + local procedure MarkPosted(var FSWorkOrder: Record "FS Work Order") + begin + FSWorkOrder.SystemStatus := FSWorkOrder.SystemStatus::Posted; + FSWorkOrder.Modify(); + end; + internal procedure UpdateWorkOrderProduct(ServiceLineArchive: Record "Service Line Archive"; var FSWorkOrderProduct: Record "FS Work Order Product") var Modified: Boolean; diff --git a/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSIntTableSubscriber.Codeunit.al b/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSIntTableSubscriber.Codeunit.al index 43ba0defb5..6bfc607fdf 100644 --- a/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSIntTableSubscriber.Codeunit.al +++ b/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSIntTableSubscriber.Codeunit.al @@ -342,6 +342,7 @@ codeunit 6610 "FS Int. Table Subscriber" FSWorkOrderProduct: Record "FS Work Order Product"; FSBookableResourceBooking: Record "FS Bookable Resource Booking"; JobJournalLine: Record "Job Journal Line"; + ServiceHeader: Record "Service Header"; ServiceLine: Record "Service Line"; ItemUnitOfMeasure: Record "Item Unit of Measure"; SourceRecordRef: RecordRef; @@ -365,6 +366,50 @@ codeunit 6610 "FS Int. Table Subscriber" if SourceFieldRef.Record().Number() = DestinationFieldRef.Record().Number() then exit; + if (SourceFieldRef.Record().Number = Database::"Service Header") and + (DestinationFieldRef.Record().Number = Database::"FS Work Order") then + case DestinationFieldRef.Name() of + FSWorkOrder.FieldName(SystemStatus): + begin + SourceFieldRef.Record().SetTable(ServiceHeader); + DestinationFieldRef.Record().SetTable(FSWorkOrder); + + case ServiceHeader.Status of + ServiceHeader.Status::Pending: + NewValue := FSWorkOrder.SystemStatus::Unscheduled; + else + NewValue := FSWorkOrder.SystemStatus; // default -> no update + end; + + IsValueFound := true; + NeedsConversion := false; + end; + end; + if (SourceFieldRef.Record().Number = Database::"FS Work Order") and + (DestinationFieldRef.Record().Number = Database::"Service Header") then + case DestinationFieldRef.Name() of + ServiceHeader.FieldName(Status): + begin + SourceFieldRef.Record().SetTable(FSWorkOrder); + DestinationFieldRef.Record().SetTable(ServiceHeader); + + case FSWorkOrder.SystemStatus of + FSWorkOrder.SystemStatus::Unscheduled, + FSWorkOrder.SystemStatus::Scheduled: + NewValue := ServiceHeader.Status::Pending; + FSWorkOrder.SystemStatus::InProgress: + NewValue := ServiceHeader.Status::"In Process"; + FSWorkOrder.SystemStatus::Completed: + NewValue := ServiceHeader.Status::Finished; + else + NewValue := ServiceHeader.Status; // default -> no update + end; + + IsValueFound := true; + NeedsConversion := false; + end; + end; + if (SourceFieldRef.Record().Number = Database::"Service Line") and (DestinationFieldRef.Record().Number = Database::"FS Work Order Product") then case DestinationFieldRef.Name() of diff --git a/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSSetupDefaults.Codeunit.al b/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSSetupDefaults.Codeunit.al index ad52ddb8b6..7923a499e7 100644 --- a/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSSetupDefaults.Codeunit.al +++ b/Apps/W1/FieldServiceIntegration/app/src/Codeunits/FSSetupDefaults.Codeunit.al @@ -572,8 +572,15 @@ codeunit 6611 "FS Setup Defaults" ServiceOrder.Reset(); ServiceOrder.SetRange("Document Type", ServiceOrder."Document Type"::Order); + FSWorkOrder.Reset(); FSWorkOrder.SetRange(IntegrateToService, true); + FSWorkOrder.SetFilter(SystemStatus, '%1|%2|%3|%4', + FSWorkOrder.SystemStatus::Unscheduled, + FSWorkOrder.SystemStatus::Scheduled, + FSWorkOrder.SystemStatus::InProgress, + FSWorkOrder.SystemStatus::Completed + ); if CDSIntegrationMgt.GetCDSCompany(CDSCompany) then FSWorkOrder.SetRange(CompanyId, CDSCompany.CompanyId); @@ -631,6 +638,13 @@ codeunit 6611 "FS Setup Defaults" IntegrationFieldMapping.Direction::Bidirectional, '', true, false); + InsertIntegrationFieldMapping( + IntegrationTableMappingName, + ServiceOrder.FieldNo(Status), + FSWorkOrder.FieldNo(SystemStatus), + IntegrationFieldMapping.Direction::Bidirectional, + '', true, false); + InsertIntegrationFieldMapping( IntegrationTableMappingName, 0,