web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Notification Issue on Posted Sales Invoice Page Based on Open Invoices in AL Extension

(1) ShareShare
ReportReport
Posted on by 2

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:

al
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:

  1. The Closed field value always shows false even when the invoice is actually closed.

  2. 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!

I have the same question (0)
  • Suggested answer
    Inkey Solutions Profile Picture
    2,122 on at
    Message('Closed Field Value: %1', PostedSalesInv."Closed")

    In the "PostedSalesInv.Closed" field, it always takes the value "No" even when the current record's "Closed" value is "Yes" in Business Central. As a result, the notification is triggered every time.

    You can use the condition PostedSalesInv.Closed = Rec.Closed for comparison instead of PostedSalesInv.Closed = false to handle the current record properly.

    Other solution:

    Refer to the current record instead of the variable.

    pageextension 50101 InvoiceStatusNotification extends "Posted Sales Invoice"
    {
        trigger OnOpenPage()
        var
            InvoiceStatusNotification: Notification;
            Text001: Label 'This invoice is still open and unpaid.';
            Text002: Label 'Trigger is firing correctly';
            OpenInvoice: Text;
        begin
            Message('Closed Field Value: %1', Rec."Closed");
            if Rec.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', Rec."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;
    }

    Thanks
  • Suggested answer
    Bilal Haider Profile Picture
    485 on at

    Your code looks fine, the field Closed is a flow field. Please add PostedSalesInv.CalcFields(Closed) after you get PostedSalsInv, then it will work.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,222 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,603 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 1,186 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans