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 sales order from job AL CODE

(0) ShareShare
ReportReport
Posted on by 8

We are creating a sales order from a job planning line using AL code, the goal is to make the warehouse shipment process from the orders, based on information stored in the jobs, this is our code.

pageextension 50121 SOfromJobPlanning extends "Job Planning Lines"
{
    layout
    {
        // Add changes to page layout here
    }

   actions
    {
        // Add changes to page actions here
        addlast(processing)
        {
            group("Create a Sales Order")
            {
                action("Sales Order")
                {
                    ApplicationArea = All;
                    trigger OnAction()
                    var
                        "Sales Ord": Record "Sales Header"; // Tabla Sales Order
                        "Sales Line": Record "Sales Line"; // Tabla Sales Lines
                        Customer: Record Customer; // Tabla Customer
                        Jobs: Record Job; // Tabla Jobs
                        SOExist: Record "Sales Header";
                        SOpage: Page "Sales Order List";
                        Items: Record Item; // Tabla de Items
                        NextLineNo: Integer;
                        


                    begin
                        Jobs.Get(Rec."Job No.");
                        Customer.Get(Jobs."Bill-to Customer No.");
                        
                        "Sales Ord".Init();
                        "Sales Ord"."Document Type" := "Sales Ord"."Document Type"::Order;
                        "Sales Ord"."No." := '';
                        "Sales Ord"."Sell-to Customer No." := Customer."No.";
                        "Sales Ord"."Sell-to Customer Name" := Customer."Name";
                        "Sales Ord".Insert(TRUE);
                        "Sales Ord".JOB := Rec."Job No.";
                        "Sales Ord"."JOB TASK" := Rec."Job Task No.";
                        "Sales Ord"."Posting Date" := Rec."Planning Date";
                        "Sales Ord".Modify(TRUE);

                       //Sales Lines
                        
                        "Sales Line".Init(); // Inicializa Sales Lines

                       "Sales Line"."Document Type" := "Sales Ord"."Document Type"::Order; //
                        "Sales Line"."Sell-to Customer No." := Customer."No.";
                        "Sales Line"."Document No." := "Sales Ord"."No.";
                        NextLineNo := NextLineNo + 10000;
                        "Sales Line"."Line No." := NextLineNo;
                        "Sales Line".Insert(true);

                       "Sales Line".Type := "Sales Line".Type::Item;
                        "Sales Line"."No." := Rec."No.";
                        "Sales Line".Description := Rec.Description;
                        "Sales Line"."Location Code" := Rec."Location Code";
                        "Sales Line"."Bin Code" := Rec."Bin Code";
                        "Sales Line".Quantity := Rec.Quantity;
                        "Sales Line"."Unit of Measure Code" := 'HARDWARE';
                        "Sales Line"."Unit Price" := Rec."Unit Cost";
                        "Sales Line"."Tax Area Code" := 'AVATAX';
                        "Sales Line"."Tax Group Code" := 'TAXABLE';
                        "Sales Line"."Line Amount" := Rec."Unit Cost";
                        "Sales Line"."Shipment Date" := Rec."Planning Date";
                        "Sales Line".Modify(true);

                   end;
                    
                }
            }
        }
    }

   var
        myInt: Integer;
}


At the moment of executing the code the sales order is created in business central with the data of the job planning line, the sales order is put in release status and when we choose the option to create the warehuse shipment the following error appears.

pastedimage1667322871398v1.png

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 77,981 Super User 2025 Season 1 on at
    RE: Create sales order from job AL CODE

    Hi, Please check a few settings below.

    Check the Require Shipemnt setting in the Location Card.

    pastedimage1667346359074v1.png

    Check the Warehouse Employees.

    pastedimage1667346400477v2.png

    Check the Location Code in the Sales Lines.

    pastedimage1667346473611v3.png

    Then release the order, and the Warehouse Shipment can be created.

    pastedimage1667346524874v4.png

    Hope this helps.
    Thanks.

    ZHU

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,274 Moderator on at

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

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,399 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans