diff --git a/CCMS/src/Customer/D4PBCCustomer.table.al b/CCMS/src/Customer/D4PBCCustomer.table.al
index 2376357..0314853 100644
--- a/CCMS/src/Customer/D4PBCCustomer.table.al
+++ b/CCMS/src/Customer/D4PBCCustomer.table.al
@@ -5,6 +5,7 @@ using D4P.CCMS.Setup;
using D4P.CCMS.Tenant;
using Microsoft.Foundation.Address;
using Microsoft.Foundation.NoSeries;
+using Microsoft.Sales.Customer;
using System.EMail;
table 62000 "D4P BC Customer"
@@ -21,6 +22,12 @@ table 62000 "D4P BC Customer"
{
Caption = 'No.';
ToolTip = 'Specifies the customer number.';
+
+ trigger OnLookup()
+ begin
+ LookupSalesCustomer();
+ end;
+
trigger OnValidate()
begin
TestNoSeries();
@@ -159,7 +166,7 @@ table 62000 "D4P BC Customer"
trigger OnInsert()
begin
if "No." = '' then begin
- CCMSSetup.Get();
+ GetCCMSSetup();
CCMSSetup.TestField("Customer Nos.");
"No. Series" := CCMSSetup."Customer Nos.";
if NoSeries.AreRelated("No. Series", xRec."No. Series") then
@@ -172,13 +179,14 @@ table 62000 "D4P BC Customer"
CCMSSetup: Record "D4P BC Setup";
PostCode: Record "Post Code";
NoSeries: Codeunit "No. Series";
+ IsCCMSSetupLoaded: Boolean;
procedure AssistEdit(OldCustomer: Record "D4P BC Customer"): Boolean
var
D4PBCCustomer: Record "D4P BC Customer";
begin
D4PBCCustomer := Rec;
- CCMSSetup.Get();
+ GetCCMSSetup();
CCMSSetup.TestField("Customer Nos.");
if NoSeries.LookupRelatedNoSeries(CCMSSetup."Customer Nos.", OldCustomer."No. Series", D4PBCCustomer."No. Series") then begin
"No." := NoSeries.GetNextNo(D4PBCCustomer."No. Series");
@@ -187,6 +195,56 @@ table 62000 "D4P BC Customer"
end;
end;
+ ///
+ /// Retrieves the CCMS setup record using a lazy-loading pattern.
+ /// Only loads the setup once by checking the IsCCMSSetupLoaded flag.
+ /// Populates the CCMSSetup global variable with the CCMS setup configuration.
+ ///
+ local procedure GetCCMSSetup()
+ begin
+ if IsCCMSSetupLoaded then
+ exit;
+
+ CCMSSetup := CCMSSetup.GetSetup();
+ IsCCMSSetupLoaded := true;
+ end;
+
+ ///
+ /// Opens the Microsoft sales customer lookup and populates this record when a customer is selected.
+ /// The lookup is only available when using Microsoft sales customers is enabled in setup.
+ ///
+ local procedure LookupSalesCustomer()
+ var
+ Customer: Record Customer;
+ begin
+ GetCCMSSetup();
+ if not CCMSSetup."Use Microsoft Sales Customer" then
+ exit;
+
+ if Page.RunModal(Page::"Customer Lookup", Customer) = Action::LookupOK then
+ PopulateFromSalesCustomer(Customer);
+ end;
+
+ ///
+ /// Populates the current CCMS customer record with data from the selected Microsoft sales customer.
+ ///
+ /// The Microsoft sales customer record to copy data from.
+ local procedure PopulateFromSalesCustomer(var Customer: Record Customer)
+ begin
+ Rec.Validate("No.", Customer."No.");
+ Rec.Validate(Name, Customer.Name);
+ Rec.Validate("Address", Customer."Address");
+ Rec.Validate("Address 2", Customer."Address 2");
+ Rec.Validate("City", Customer."City");
+ Rec.Validate("Post Code", Customer."Post Code");
+ Rec.Validate(County, Customer.County);
+ Rec.Validate("Country/Region Code", Customer."Country/Region Code");
+ Rec.Validate("Contact Person Name", Customer.Contact);
+ Rec.Validate("Contact Person Email", Customer."E-Mail");
+
+ OnAfterPopulateFromSalesCustomer(Rec, xRec, Customer);
+ end;
+
local procedure TestNoSeries()
var
D4PBCCustomer: Record "D4P BC Customer";
@@ -199,7 +257,7 @@ table 62000 "D4P BC Customer"
if "No." <> xRec."No." then
if not D4PBCCustomer.Get(Rec."No.") then begin
- CCMSSetup.Get();
+ GetCCMSSetup();
NoSeries.TestManual(CCMSSetup."Customer Nos.");
"No. Series" := '';
end;
@@ -214,6 +272,11 @@ table 62000 "D4P BC Customer"
MailManagement.CheckValidEmailAddresses("Contact Person Email");
end;
+ [IntegrationEvent(false, false)]
+ local procedure OnAfterPopulateFromSalesCustomer(var D4PBCCustomer: Record "D4P BC Customer"; xD4PBCCustomer: Record "D4P BC Customer"; MicrosoftSalesCustomer: Record Customer)
+ begin
+ end;
+
[IntegrationEvent(false, false)]
local procedure OnBeforeTestNoSeries(var D4PBCCustomer: Record "D4P BC Customer"; xD4PBCCustomer: Record "D4P BC Customer"; var IsHandled: Boolean)
begin
diff --git a/CCMS/src/Setup/D4PBCSetup.page.al b/CCMS/src/Setup/D4PBCSetup.page.al
index c485a7e..4a79e55 100644
--- a/CCMS/src/Setup/D4PBCSetup.page.al
+++ b/CCMS/src/Setup/D4PBCSetup.page.al
@@ -20,6 +20,9 @@ page 62010 "D4P BC Setup"
field("Debug Mode"; Rec."Debug Mode")
{
}
+ field("Use Microsoft Sales Customer"; Rec."Use Microsoft Sales Customer")
+ {
+ }
}
group(Numbering)
{
diff --git a/CCMS/src/Setup/D4PBCSetup.table.al b/CCMS/src/Setup/D4PBCSetup.table.al
index d546daa..5c6e2e1 100644
--- a/CCMS/src/Setup/D4PBCSetup.table.al
+++ b/CCMS/src/Setup/D4PBCSetup.table.al
@@ -35,6 +35,11 @@ table 62009 "D4P BC Setup"
TableRelation = "No. Series";
ToolTip = 'Specifies the number series used to assign customer numbers automatically.';
}
+ field(6; "Use Microsoft Sales Customer"; Boolean)
+ {
+ Caption = 'Use Microsoft Sales Customer';
+ ToolTip = 'Specifies whether to use Microsoft Sales Customer table relation.';
+ }
}
keys