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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Print Text On Report If ....

(0) ShareShare
ReportReport
Posted on by 5

Hallo Community,

I have an task to do in Business Central for one of our customers and i don't really know why my code is not working.

Every time when creating a new Sales Order and choosing a Customer, my code should check the Customer table and verify if the fields "VAT Registration No" <> ' ' and "Country/Regeion Code"  <> 'DE'.

If the conditions are true, then a text should be printed on the Sales Invoice Report after being posted

This is what i have: 

codeunit 50100 SalesPostSubscriber
{
    var
        recSalesInvHdr: Record "Sales Invoice Header";
        recCustomer: Record Customer;



    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterPostSalesDoc', '', false, false)]
    procedure AddVATText_AfterSalesPost(VAR SalesHeader: Record "Sales Header"; VAR GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line"; SalesShptHdrNo: Code[20]; RetRcpHdrNo: Code[20]; SalesInvHdrNo: Code[20]; SalesCrMemoHdrNo: Code[20]; CommitIsSuppressed: Boolean)
    var
        char_LF: Char;
    begin
        recCustomer.SetRange("No.", SalesHeader."Sell-to Customer No.");
        recCustomer.FindFirst();
        char_LF := 10;

        if SalesInvHdrNo <> '' then
            if (recCustomer."VAT Registration No." <> '') and (SalesHeader."Sell-to Country/Region Code" <> 'DE') then
                recSalesInvHdr.SetRange("No.", SalesInvHdrNo);
        recSalesInvHdr.FindFirst();
        recSalesInvHdr.CustVATText := 'Ust-freie innergemeinschaftliche Lieferung i.S. $4 Nr. 1b in Verbindung mit §6a UStG.' + FORMAT(char_LF) +
                                                           'Ihre EG-IdentNr.:' + recCustomer."VAT Registration No.";
        recSalesInvHdr.Modify();

    end;
I also had to extend the Sales Invoice Header Table by one Field: CustVATText which i did as follow: 
tableextension 50100 ExtendSalesInvoiceHdr extends "Sales Invoice Header"
{
    fields
    {
        field(50100; CustVATText; Text[2048])
        {
        }
    }
}
After that i added the field in the DataSet of the Sales Invoice Header Report, but like I mentioned, nothing's happen.
I would be really grateful if someone could help.
Thany you for your time!
 
Paul
I have the same question (0)
  • riya patel Profile Picture
    82 on at

    Did you check on the table is there any data on field custVATText or not?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,870 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,138 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 915 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans