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.
{
[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;
PostedSalesInvHdr.CalcFields("Amount Including VAT"); // ✅ ensure amount is loaded
Customer.CalcFields(Balance, "Balance (LCY)"); // ✅ ensure balance is accurate
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;
}


Report
All responses (
Answers (