Hi,
I am heaving troubles to create a Sales Invoice via AL Extension.
I have build an AL Extension, where my employees track certain activities based on their resource.
Now i try to implement, the creation of a Sales Invoice, but the Invoice does not get saved:
procedure InvoiceTickets_SD(var consolidate: Boolean)
var
tickets: Record Tickets_SD;
ticketlines: Record "Ticket Lines_SD";
sh: Record "Sales Header";
sl: Record "Sales Line";
SalesSetup: Record "Sales & Receivables Setup";
begin
// Filter
tickets.SetRange("Ticket Status", tickets."Ticket Status"::"On Hold");
// Get Tickets
if tickets.FindSet() then
repeat
// Ticket Header, Create Sales Header
SalesSetup.Reset();
sh.Reset();
SalesSetup.Get;
sh.Init();
sh."Document Type" := sh."Document Type"::Invoice;
SalesSetup.TestField("Invoice Nos.");
sh."Sell-to Customer No." := tickets."Customer No.";
sh.Validate("Sell-to Customer No.");
sh."Posting Date" := WorkDate;//Today;
sh.Validate("Posting Date");
sh.Insert(true);
sh.InitFromSalesHeader(sh);
sh.Validate("Sell-to Customer No.", tickets."Customer No.");
sh.Modify;
// load ticket lines
ticketlines.SetRange("Ticket No.", tickets."No.");
if ticketlines.FindSet() then
repeat
// Create Sales Lines
sl.Init();
until ticketlines.Next() = 0;
until tickets.Next() = 0;
end;
}
What am i doing wrong ?
Thanks for any help