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...
Suggested Answer

Create Sales Invoice via AL

(0) ShareShare
ReportReport
Posted on by 45

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

  • Suggested answer
    Mohana Yadav Profile Picture
    61,260 Super User 2026 Season 2 on at

    1st question: do you have any records in "Tickets_SD" table with status "On Hold"?

  • -Chris- Profile Picture
    45 on at

    yes i do, because this is still in development, i fetched all tickets with status on hold

    the records get populated, but when i hit the next ticket it always says the sales invoice number exists in table ... and it does not create the next one ....

    and the sales invoices page is still empty

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 645 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 432 Super User 2026 Season 2

#3
Teagen Boll Profile Picture

Teagen Boll 248 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans