How to do it...

  1. Extract ch6-design-pattern-discovery.zip to a folder on your machine and copy/paste the following files into your alExtensibleAppProject folder. Make sure to replace the following files with the ones you extracted:
    • Post Transaction.al
    • Transaction Entry.al
    • Transaction Worksheet.al
    • Post Transaction Action.al
    • Handle Post Transaction Action.al

Now, open the alExtensibleAppProject folder in Visual Studio Code.

  1. The first thing we need to do is add an event that can be subscribed to in order to add new post actions.

In Explorer, select Post Transaction Action.al and add the following event publisher to the table:

[IntegrationEvent(false, false)]
procedure OnAddPostTransactionAction(var TempPostTransactionAction: Record "Post Transaction Action" temporary)
begin
end;

Subscribers to this event will be responsible for adding new entries to the temporary table.

  1. Now, let's build the page to display the list of available post actions. Instead of simply displaying the records in the table, we need this page to be dynamic and discover any actions that have been added to the system.

In Explorer, create a new file named Post Transaction Actions.al and in the Editor, create a new list page object, as shown in the following code:

page 50004 "Post Transaction Actions"
{
PageType = List;
ApplicationArea = All;
UsageCategory = Lists;
SourceTable = "Post Transaction Action";
SourceTableTemporary = true;
Editable = false;

layout
{
area(Content)
{
repeater(GroupName)
{
field(Code; Code)
{
ApplicationArea = All;
}
field(Description; Description)
{
ApplicationArea = All;
}
field("Codeunit No."; "Codeunit No.")
{
ApplicationArea = All;
}
}
}
}
}
Since the page contents will be built dynamically, we need to set the page to not be editable and make the source table temporary. Physical records will never be written to the table.
  1. When the page opens, we need to raise the OnAddPostTransactionAction() event in order to build the temporary table that the page will display. Add the following code to the page:
trigger OnOpenPage()
begin
OnAddPostTransactionAction(Rec);
end;
  1. Open the alExtensibleAppProject folder in Visual Studio Code. Let's build and deploy the application and confirm the list of available post-transaction actions.

Press F5 to build and deploy the app to your AL development sandbox.

Once you log in, follow these steps:

    1. Use  to search for Transaction Worksheet and click on the link to open it.
    2. Add a new transaction record.
    3. Scroll to the right side of the line and drill down on the Post Transaction Action field.

You should see an empty list as no actions have been added to the system.

  1. For this step, let's now pretend that we're the customer that wants to have a specific post action take place for some transactions.

We will use the same project for this step, but typically, the customer would do this in their own extension.

In Explorer, create a file named Add Custom Post Actions.al and in the Editor, create a new codeunit object and a subscriber to the OnAddPostTransactionAction() event that we created earlier:

codeunit 50003 "Add Custom Post Actions"
{
[EventSubscriber(ObjectType::Table, Database::
"Post Transaction Action", 'OnAddPostTransactionAction',
'', false, false)]
local procedure OnAddPostTransactionAction(
var TempPostTransactionAction: Record
"Post Transaction Action")
begin
AddCustomPostTransactionActions(
TempPostTransactionAction);
end;
}
  1. Now, add a function to create some new Post Transaction Action entries:
local procedure AddCustomPostTransactionActions(var TempPostTransactionAction: Record "Post Transaction Action")
var
Action1Code: Label 'ACTION1';
Action1Desc: Label 'Action 1';
Action2Code: Label 'ACTION2';
Action2Desc: Label 'Action 2';
begin
if not TempPostTransactionAction.Get(Action1Code) then begin
TempPostTransactionAction.Init();
TempPostTransactionAction.Code := Action1Code;
TempPostTransactionAction.Description := Action1Desc;
TempPostTransactionAction."Codeunit No." := 0;
TempPostTransactionAction.Insert();
end;

if not TempPostTransactionAction.Get(Action2Code) then begin
TempPostTransactionAction.Init();
TempPostTransactionAction.Code := Action2Code;
TempPostTransactionAction.Description := Action2Desc;
TempPostTransactionAction."Codeunit No." := 0;
TempPostTransactionAction.Insert();
end;
end;
  1. Now, press F5 to build and deploy the app to your sandbox.

Once you log in, follow these steps:

    1. Use  to search for Transaction Worksheet and click on the link to open it.
    2. Add a new transaction record.
    3. Scroll to the right side of the line and drill down on the Post Transaction Action field.

You should now see the two actions that you created with your subscriber.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.183.153