Skip to main content

Notifications

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

Create sales order from job AL CODE

Posted on by 87

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 71,565 Super User 2024 Season 2 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,264 Super User 2024 Season 1 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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,900 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,275 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans