Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Create multiple sales Headers

(0) ShareShare
ReportReport
Posted on by 5

I am developing a Extension using AL Language  to create multiple Sales invoices.  So I need to create Multiple sales Header records and each sale Header record having only one Sales Line.

First sales header and sales line record create successfully and when creating 2nd record and assign value to  "Sell-to Customer No." I am getting below error
"If you change sell-to customer, the existing sales line will be deleted and new sales
line based on the new information on the header will be created "
below is the logic I have implement
for RowNo := 2 to Rows do begin
SalesHeader.Init();
                SalesHeader.Validate("Document Type", SalesHeader."Document Type"::Invoice);
                SalesHeader.Validate("Sell-to Customer No.", CustomerNo);
                SalesHeader.Validate("Bill-to Customer No.", SalesHeader."Sell-to Customer No.");
                if SalesHeader.Insert(true) then begin
                 
                 SalesLine.Init();
                 //other lines come below
                end

end

  • Thilina Profile Picture
    5 on at
    RE: Create multiple sales Headers

    Thanks Bidhi , great help . Resolved the issue adding

    clear(SalesHeader);  

  • Suggested answer
    Bodhi Profile Picture
    558 on at
    RE: Create multiple sales Headers

    clear(SalesHeader);  //add this line first

    SalesHeader.Init();

                   SalesHeader.Validate("Document Type", SalesHeader."Document Type"::Invoice);

                   SalesHeader.Validate("Sell-to Customer No.", CustomerNo);

                   SalesHeader.Validate("Bill-to Customer No.", SalesHeader."Sell-to Customer No.");

                   if SalesHeader.Insert(true) then begin

  • Alexei Pavlov Profile Picture
    20 on at
    RE: Create multiple sales Headers

    Remove "SalesHeader.Validate("Bill-to Customer No.", SalesHeader."Sell-to Customer No.");" line.

    There is no need to do it. Read standard validation code for "Sell-To Customer No." field.

  • Suggested answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    13,637 Moderator on at
    RE: Create multiple sales Headers

    When you use Init, primary keys are not initialized.

    You need to initialize the document number first, otherwise it will still refer to the 1st record.

    example:

    SalesHeader.Validate("No.",'');

  • Suggested answer
    Andy Sather Profile Picture
    on at
    RE: Create multiple sales Headers

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

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 Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 536 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 400

#3
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 384

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans