Skip to main content

Notifications

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
  • riya patel Profile Picture
    82 on at
    RE: Print Text On Report If ....

    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,217 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,978 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans