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

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,204 Super User 2026 Season 1 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,823 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,011 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 628 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans