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