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

Community site session details

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

SMS integration logic to trigger after posting via the Post button

(0) ShareShare
ReportReport
Posted on by
I added SMS integration logic to trigger after posting via the Post button, and it works correctly — the browser opens and the SMS is sent to the customer.
However, I noticed that the SMS is also being sent when using Posting Preview, which should not happen. Can anyone advise why the Preview Posting process is triggering the same SMS logic? I urgently need the correct approach to prevent SMS from sending during Preview Posting.
The code unit reference is attached below. Your quick guidance would be greatly appreciated.
 
codeunit 50331 "Sales Order Post SMS Auto"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterPostSalesDoc', '', false, false)]
    local procedure OnAfterPostSalesDoc(
        SalesHeader: Record "Sales Header";
        GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line";
        SalesShptHdrNo: Code[20];
        SalesInvHdrNo: Code[20])
    var
        SMSCodeunit: Codeunit "Sales Order SMS Browser";
        Customer: Record Customer;
        PostedSalesInvHdr: Record "Sales Invoice Header";
    begin
        // ✅ Send only for invoices
        if SalesInvHdrNo = '' then
            exit;
        if PostedSalesInvHdr.Get(SalesInvHdrNo) then begin
            PostedSalesInvHdr.CalcFields("Amount Including VAT"); // ✅ ensure amount is loaded
            if Customer.Get(PostedSalesInvHdr."Sell-to Customer No.") then begin
                Customer.CalcFields(Balance, "Balance (LCY)"); // ✅ ensure balance is accurate
                if Customer."Phone No." <> '' then
                    SMSCodeunit.SendSMSViaBrowser(
                        PostedSalesInvHdr."Sell-to Customer Name",
                        PostedSalesInvHdr."No.", // ✅ Posted Invoice No.
                        PostedSalesInvHdr."Amount Including VAT", // ✅ Actual Invoice Amount
                        Customer."Balance (LCY)", // ✅ Up-to-date Remaining Balance
                        Customer."Phone No.")
                else
                    Message('⚠️ No phone number found for customer %1', Customer."No.");
            end else
                Message('⚠️ Customer not found.');
        end;
    end;
}
I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,888

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 3,386 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 2,041 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans