Hello everyone,
I'm currently working on an AL extension for Business Central where I need to trigger a notification on the "Posted Sales Invoice" page when the invoice is not closed (i.e., when the invoice is still open). Here is the code I've written:
pageextension 50101 InvoiceStatusNotification extends "Posted Sales Invoice"
{
trigger OnOpenPage()
var
PostedSalesInv: Record "Sales Invoice Header";
InvoiceStatusNotification: Notification;
Text001: Label 'This invoice is still open and unpaid.';
Text002: Label 'Trigger is firing correctly';
OpenInvoice: Text;
begin
// Check if the record is found
if PostedSalesInv.Get(Rec."No.") then begin
// Debug message to check the value of the Closed field
Message('Closed Field Value: %1', PostedSalesInv."Closed");
if PostedSalesInv.Closed = false then begin
// Create the notification
InvoiceStatusNotification.Message(Text001);
InvoiceStatusNotification.Scope := NotificationScope::LocalScope;
// Add a data property for the invoice number
InvoiceStatusNotification.SetData('InvNumber', PostedSalesInv."No.");
// Add an action that calls the ActionHandler codeunit
InvoiceStatusNotification.AddAction(OpenInvoice, Codeunit::"InvoiceActionHandler", 'OpenInvoice');
// Send the notification to the client
InvoiceStatusNotification.Send();
// Debug message to confirm notification is sent
Message('Notification Sent');
end;
end else begin
// Debug message if record is not found
Message('Record not found for Invoice No.: %1', Rec."No.");
end;
end;
}
Despite my efforts, the notification appears even on closed invoices. The goal is for the notification to appear only when the invoice is open. Here are some details:
-
The
Closed
field value always showsfalse
even when the invoice is actually closed. -
My goal is to send a notification when the invoice is open (i.e., not closed).
I've tried using the OnAfterGetRecord
trigger and am currently using the OnOpenPage
trigger, but neither seems to work consistently. Any insights or suggestions on why the notification might not be triggering correctly and how to resolve this issue would be greatly appreciated.
Thanks in advance for your help!