Looking at the subject there are lot of blogs available but I am writing this based on one of the request from my colleague.
Everybody aware of that whenever you developed an app it need to be extensible and if anybody would like to add or modify any field or additional routing we need to have events which can extend the base functionality.
Step 1 :- Simple Quick action to add event in Business Central
Next step will be we can subscribe the event and add you own code.
It is so simple to add custom event in AL and allow other to extend your functionality.
A core part of extension-based development is the use of events and event subscribers. Use the new Shift+Alt+E shortcut in the AL code editor to invoke a list of all events.
Today we will see how we can substitute our own document report with Standard report in business central.
To override report we need to use ReportManaagement Codeunit and from that we need to use OnAfterSubstituteReport event
Suppose we have created own customize report called ‘Detail Inventory Transaction’ and now we have to replace standard report for Inventory Transaction Detail
[EventSubscriber(ObjectType::Codeunit, 44, 'OnAfterSubstituteReport', '', true, true)]
procedure SubstituteInventoryTransactionReport(ReportId: Integer; var NewReportId: Integer)
begin
If ReportId = Report::"Inventory - Transaction Detail" then
NewReportId := Report::"Detail Inventory Transaction";
end;
Publish your extension and check the report .You will find new report is substituted with standard report.
As you aware that with new version of business central comes up breaking changes which actually change the way of writing few points like assisted setup and many more.
Today we will see how to create assisted setup in wave 2 with new events. In this document have created one of the most simple assisted setup.
Step 3 :- Now use new assisted setup module to create assisted setup as below
codeunit 50100 "SetupTableAssistedSetup"
{
var
AssistedSetup: Codeunit "Assisted Setup";
AssistedSetupGroup: Enum "Assisted Setup Group";
CurrentGlobalLanguage: Integer;
SetupWizardTxt: Label 'Set up Table';
SetupWizardLinkTxt: Label 'https://google.com', Locked = true;
AlreadySetUpQst: Label 'Setup is already set up. To change settings for it, go to the setup again.Do you want go there now ?';
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Assisted Setup", 'OnRegister', '', false, false)]
local procedure SetupInitialize()
begin
CurrentGlobalLanguage := GlobalLanguage();
AssistedSetup.Add(GetAppId(), PAGE::SetupPage, SetupWizardTxt, AssistedSetupGroup::Extensions, '', SetupWizardLinkTxt);
GLOBALLANGUAGE(1033);
AssistedSetup.AddTranslation(GetAppId(), PAGE::SetupPage, 1033, SetupWizardTxt);
GLOBALLANGUAGE(CurrentGlobalLanguage);
GetInformationSetupStatus();
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Assisted Setup", 'OnReRunOfCompletedSetup', '', false, false)]
local procedure OnReRunOfCompletedSetup(ExtensionId: Guid; PageID: Integer; var Handled: Boolean)
begin
if ExtensionId <> GetAppId() then
exit;
case PageID of
Page::"Assisted Company Setup Wizard":
begin
if Confirm(AlreadySetUpQst, true) then
Page.Run(PAGE::SetupPage);
Handled := true;
end;
end;
end;
local procedure GetAppId(): Guid
var
Info: ModuleInfo;
EmptyGuid: Guid;
begin
if Info.Id() = EmptyGuid then
NavApp.GetCurrentModuleInfo(Info);
exit(Info.Id());
end;
local procedure GetInformationSetupStatus()
var
SetupTab: Record SetupTable;
begin
SetupTab.SetFilter(GroupCode, '<>%1', '');
If SetupTab.IsEmpty() then
exit;
AssistedSetup.Complete(GetAppId(), Page::SetupPage);
end;
}
Publish the extension and you will see following result.