Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

What is the proper way to insert a line in Sales order line.

(0) ShareShare
ReportReport
Posted on by 450

So i've made a button that inserts a line into my sales order lines. Now I know that some fields on a line normally get filled in once the saleline number and type are validated. At the moment do do not have this implemented yet in my code to add a line when i click a button.

The code i have now is following:

procedure InsertFreightCost(SalesLine: Record "Sales Line"; Price: Decimal; DocType: Option; DocNumb: Code[20]; DocDate: Date);
    var
        LineNo: Integer;
    begin
        SalesLine.Init();
        SalesLine.SetFilter("Document No.", DocNumb);
        SalesLine.FindSet();
        if SalesLine.FindLast() then
            LineNo := SalesLine."Line No." + 10000
        else
            LineNo := 10000;
        SalesLine."Line No." := LineNo;
        SalesLine."Document Type" := DocType;
        SalesLine."Document No." := DocNumb;
        SalesLine.Type := SalesLine.Type::"G/L Account";
        SalesLine."No." := '700010';
        SalesLine."Description" := 'Selling. - EU';
        SalesLine.Quantity := 1;
        SalesLine."Unit of Measure Code" := 'PIECES';
        SalesLine."Unit Price" := Price;
        SalesLine."Line amount" := Price;
        SalesLine."Qty. to Ship" := 1;
        SalesLine."Qty. to Invoice" := 1;
        SalesLine."Shipment Date" := DocDate;
        SalesLine."Planned Shipment Date" := DocDate;
        SalesLine."Planned Delivery Date" := DocDate;
        SalesLine."Qty. to Ship" := 1;
        SalesLine."Qty. to Invoice" := 1;
        SalesLine."Return Qty. to Receive" := 0;
        SalesLine.Insert();
    end;
So this works but i know it's not the correct way of doing this. How do i change this so that i only need to fill in the required fields and the others will fill themselves in based on the required fields?

*This post is locked for comments

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 on at
    RE: What is the proper way to insert a line in Sales order line.

    Use this

       procedure InsertFreightCost(SalesLine: Record "Sales Line"; Price: Decimal; DocType: Option; DocNumb: Code[20]; DocDate: Date);

       var

           LineNo: Integer;

       begin

           SalesLine.Reset;

    SalesLine.SetRange("Document Type",DocType);

    SalesLine.SetRange("Document No.",DocNumb);

    if SalesLine.FindLast() then

               LineNo := SalesLine."Line No." + 10000

           else

               LineNo := 10000;

    SalesLine.Init();

           SalesLine."Document Type" := DocType;

           SalesLine."Document No." := DocNumb;

           SalesLine."Line No." := LineNo;        

           SalesLine.Type := SalesLine.Type::"G/L Account";

           SalesLine.Validate("No.",'700010');

           SalesLine."Description" := 'Selling. - EU';

           SalesLine.Validate(Quantity,1);

           SalesLine."Unit of Measure Code" := 'PIECES';

           SalesLine."Unit Price" := Price;

           SalesLine."Line amount" := Price;

           SalesLine."Qty. to Ship" := 1;

           SalesLine."Qty. to Invoice" := 1;

           SalesLine."Shipment Date" := DocDate;

           SalesLine."Planned Shipment Date" := DocDate;

           SalesLine."Planned Delivery Date" := DocDate;

           SalesLine."Qty. to Ship" := 1;

           SalesLine."Qty. to Invoice" := 1;

           SalesLine."Return Qty. to Receive" := 0;

           SalesLine.Insert(True);

       end;

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans