A minimal extension using D2K Companies House Lookup
Last updated
This page is a complete worked example of a Business Central extension that depends on D2K Companies House Lookup. It is part of the developer guide, Building on D2K Companies House Lookup; the calls it makes are described in The D2K Companies House Lookup API.
A status check that a dependant might put behind a Release action, and a subscriber that records filings:
namespace MyCompany.MyApp;
using D2K.CompaniesHouseLookup;
codeunit 50100 "MYA Company Checks"
{
procedure IsCustomerActive(Customer: Record Customer): Boolean
var
DefaultResolver: Codeunit "D2KL Default Resolver";
LookupDialog: Page "D2KL Company Lookup Dialog";
Resolver: Interface "D2KL ICH Resolver";
CRN: Code[8];
begin
Resolver := DefaultResolver;
if not Resolver.IsConfigured() then
exit(true); // no key in this company: do not block the user
CRN := LookupDialog.NormaliseCRN(Customer."Registration Number");
if not Resolver.ValidateCRNFormat(CRN) then
exit(true);
exit(Resolver.GetCompanyStatus(CRN) = "D2KL Company Status"::Active);
end;
procedure WatchCustomer(Customer: Record Customer)
var
FilingWatchMgt: Codeunit "D2KL Filing Watch Mgt";
LookupDialog: Page "D2KL Company Lookup Dialog";
begin
FilingWatchMgt.RegisterWatch(LookupDialog.NormaliseCRN(Customer."Registration Number"), 'My App');
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"D2KL Events", OnFilingEventReceived, '', false, false)]
local procedure RecordFilingOnFilingEventReceived(var FilingEvent: Record "D2KL Filing Event")
var
FilingAlert: Record "MYA Filing Alert";
begin
if FilingAlert.Get(FilingEvent.CRN, FilingEvent."Source Transaction Id") then
exit; // already recorded: the poller can notify twice after a failed run
FilingAlert.Init();
FilingAlert.CRN := FilingEvent.CRN;
FilingAlert."Source Transaction Id" := FilingEvent."Source Transaction Id";
FilingAlert."Filing Type" := FilingEvent."Filing Type";
FilingAlert."Filing Date" := FilingEvent."Filing Date";
FilingAlert.Description := FilingEvent.Description;
FilingAlert.Insert();
end;
}