Sales order with multiple line using C/al-code.

ManiNav
Member Posts: 120
Hi Everyone, [Nav 2018]
I am trying to create sales order with multiple line using Cal/code. I am able to create SO with single line but not able to insert multiple line. This is my code,
Item.INIT;
Item."No." := '2007';
ItemUnitOfMeasure."Item No." := Item."No.";
ItemUnitOfMeasure.Code := 'PCS';
ItemUnitOfMeasure.INSERT;
Item."Base Unit of Measure" := ItemUnitOfMeasure.Code;
Item."Inventory Posting Group" := 'RESALE';
Item.INSERT(TRUE);
SalesHeader.INIT;
SalesHeader."Document Type" := SalesHeader."Document Type"::Order;
SalesHeader."No." :=Item."No.";
SalesHeader."Sell-to Customer No." := '10000';
SalesHeader.VALIDATE("Sell-to Customer No.", '10000');
SalesHeader."Bill-to Customer No." := SalesHeader."Sell-to Customer No.";
SalesHeader."Posting Date" := WORKDATE;
SalesHeader."Document Date" := SalesHeader."Posting Date";
SalesHeader."Due Date" := SalesHeader."Posting Date";
SalesHeader.Ship := TRUE;
SalesHeader.Invoice := TRUE;
SalesHeader."Shipping No. Series" := 'S-SHPT';
SalesHeader."Posting No. Series" := 'S-INV+';
SalesHeader."Dimension Set ID" := 4;
SalesHeader.INSERT(TRUE);
SalesLine.INIT;
SalesLine."Document Type" := SalesHeader."Document Type";
SalesLine."Document No." := SalesHeader."No.";
SalesLine.Type := SalesLine.Type::Item;
SalesLine.SETRANGE("Document Type",SalesHeader."Document Type");
SalesLine.SETRANGE("Document No.",SalesHeader."No.");
SalesLine."Line No." := NextLineNo;
//FOR SalesLine."No." := <1000> TO <1001> DO
IF SalesLine.FIND('+') THEN
NextLineNo := SalesLine."Line No." + 10000
ELSE
NextLineNo := 10000;
SalesLine."No." := '1000';
SalesLine.VALIDATE("No.",'1000');
//SalesLine."No." := '1001';
//SalesLine.VALIDATE("No.",'1001');
Quantity := 7;
SalesLine.Quantity := Quantity;
SalesLine."Quantity (Base)":= SalesLine.Quantity;
SalesLine."Qty. to Invoice" := SalesLine.Quantity;
SalesLine."Qty. to Invoice (Base)" := SalesLine.Quantity;
SalesLine."Qty. to Ship" := SalesLine.Quantity;
SalesLine."Qty. to Ship (Base)" := SalesLine.Quantity;
SalesLine."Gen. Prod. Posting Group" := 'RETAIL';
SalesLine."Gen. Bus. Posting Group" := 'DOMESTIC';
SalesLine."VAT Bus. Posting Group" := '';
SalesLine."VAT Prod. Posting Group" := '';
SalesLine."VAT Calculation Type" := SalesLine."VAT Calculation Type"::"Reverse Charge VAT";
SalesLine.INSERT(TRUE);
CODEUNIT.RUN(CODEUNIT::"Sales-Post",SalesHeader);
Please, guide me how can i insert multiple line in SO. e.g. I am trying to inset item no '1001' after '1000' and so on.
Thanks in advance,
Mani
I am trying to create sales order with multiple line using Cal/code. I am able to create SO with single line but not able to insert multiple line. This is my code,
Item.INIT;
Item."No." := '2007';
ItemUnitOfMeasure."Item No." := Item."No.";
ItemUnitOfMeasure.Code := 'PCS';
ItemUnitOfMeasure.INSERT;
Item."Base Unit of Measure" := ItemUnitOfMeasure.Code;
Item."Inventory Posting Group" := 'RESALE';
Item.INSERT(TRUE);
SalesHeader.INIT;
SalesHeader."Document Type" := SalesHeader."Document Type"::Order;
SalesHeader."No." :=Item."No.";
SalesHeader."Sell-to Customer No." := '10000';
SalesHeader.VALIDATE("Sell-to Customer No.", '10000');
SalesHeader."Bill-to Customer No." := SalesHeader."Sell-to Customer No.";
SalesHeader."Posting Date" := WORKDATE;
SalesHeader."Document Date" := SalesHeader."Posting Date";
SalesHeader."Due Date" := SalesHeader."Posting Date";
SalesHeader.Ship := TRUE;
SalesHeader.Invoice := TRUE;
SalesHeader."Shipping No. Series" := 'S-SHPT';
SalesHeader."Posting No. Series" := 'S-INV+';
SalesHeader."Dimension Set ID" := 4;
SalesHeader.INSERT(TRUE);
SalesLine.INIT;
SalesLine."Document Type" := SalesHeader."Document Type";
SalesLine."Document No." := SalesHeader."No.";
SalesLine.Type := SalesLine.Type::Item;
SalesLine.SETRANGE("Document Type",SalesHeader."Document Type");
SalesLine.SETRANGE("Document No.",SalesHeader."No.");
SalesLine."Line No." := NextLineNo;
//FOR SalesLine."No." := <1000> TO <1001> DO
IF SalesLine.FIND('+') THEN
NextLineNo := SalesLine."Line No." + 10000
ELSE
NextLineNo := 10000;
SalesLine."No." := '1000';
SalesLine.VALIDATE("No.",'1000');
//SalesLine."No." := '1001';
//SalesLine.VALIDATE("No.",'1001');
Quantity := 7;
SalesLine.Quantity := Quantity;
SalesLine."Quantity (Base)":= SalesLine.Quantity;
SalesLine."Qty. to Invoice" := SalesLine.Quantity;
SalesLine."Qty. to Invoice (Base)" := SalesLine.Quantity;
SalesLine."Qty. to Ship" := SalesLine.Quantity;
SalesLine."Qty. to Ship (Base)" := SalesLine.Quantity;
SalesLine."Gen. Prod. Posting Group" := 'RETAIL';
SalesLine."Gen. Bus. Posting Group" := 'DOMESTIC';
SalesLine."VAT Bus. Posting Group" := '';
SalesLine."VAT Prod. Posting Group" := '';
SalesLine."VAT Calculation Type" := SalesLine."VAT Calculation Type"::"Reverse Charge VAT";
SalesLine.INSERT(TRUE);
CODEUNIT.RUN(CODEUNIT::"Sales-Post",SalesHeader);
Please, guide me how can i insert multiple line in SO. e.g. I am trying to inset item no '1001' after '1000' and so on.
Thanks in advance,
Mani
0
Answers
-
Comment removedFor help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.0
-
Hi SanderDk,
Thank you for the reply.
I tried already that things,but after that its take only the second item in the line. so, my requirement is to add multiple line. please guide me further.
Thanks,
Mani0 -
well if it were me I would do something like create a codeunit with som functions:
CLEAR(SalesHeader); CreateSalesHeader(SalesHeader); //Add loop for the item you want to create sales line for. CreateSalesLine(SalesHeader,'1000');
LOCAL CreateSalesHeader(VAR SalesHeader : Record "Sales Header") SalesHeader.INIT; SalesHeader.VALIDATE("Document Type",SalesHeader."Document Type"::Order); SalesHeader.INSERT(TRUE); //Add code to handle Sell-to Customer and so on. //if you change any field remember to end with SalesHeader.MODIFY(TRUE);
LOCAL CreateSalesLine(SalesHeader : Record "Sales Header";ItemNo : Code[20]) SalesLine.INIT; SalesLine.VALIDATE("Document Type",SalesHeader."Document Type"); SalesLine.VALIDATE("Document No.",SalesHeader."No."); SalesLine.VALIDATE("Line No.",GetNextLineNo(SalesHeader)); SalesLine.INSERT(TRUE); SalesLine.VALIDATE(Type,SalesLine.Type::Item); SalesLine.VALIDATE("No.",ItemNo); SalesLine.MODIFY(TRUE); //Add code to handle quanty and so on //if you change any field remember to end with SalesLine.MODIFY(TRUE);
LOCAL GetNextLineNo(SalesHeader : Record "Sales Header") LineNo : Integer SalesLine.SETRANGE("Document Type",SalesHeader."Document Type"); SalesLine.SETRANGE("Document No.",SalesHeader."No."); IF SalesLine.FINDLAST THEN LineNo := SalesLine."Line No."; LineNo += 10000;
For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.0 -
Hi SanderDk,
How can i add loop for the item that i want to create sales line for. [If i want to add item: 1000(Bicycle), and 1001(Touring Bicycle)...] please guide me.
here is my code:
Item.INIT;
Item."No." := 'Bicycle';
//Item."No." := 'Touring Bicycle';
ItemUnitOfMeasure."Item No." := Item."No.";
ItemUnitOfMeasure.Code := 'PCS';
ItemUnitOfMeasure.INSERT(TRUE);
Item."Base Unit of Measure" := ItemUnitOfMeasure.Code;
Item."Inventory Posting Group" := 'RESALE';
Item.INSERT;
SalesHeader.INIT;
SalesHeader."Document Type" := SalesHeader."Document Type"::Order;
SalesHeader."No." :='2011';
SalesHeader."Sell-to Customer No." := '10000';
SalesHeader.VALIDATE("Sell-to Customer No.", '10000');
SalesHeader."Bill-to Customer No." := SalesHeader."Sell-to Customer No.";
SalesHeader."Posting Date" := WORKDATE;
SalesHeader."Document Date" := SalesHeader."Posting Date";
SalesHeader."Due Date" := SalesHeader."Posting Date";
SalesHeader.Ship := TRUE;
SalesHeader.Invoice := TRUE;
SalesHeader."Shipping No. Series" := 'S-SHPT';
SalesHeader."Posting No. Series" := 'S-INV+';
SalesHeader."Dimension Set ID" := 4;
SalesHeader.INSERT(TRUE);
SalesLine.INIT;
SalesLine.VALIDATE("Document Type",SalesHeader."Document Type");
SalesLine.VALIDATE("Document No.",SalesHeader."No.");
SalesLine.INSERT(TRUE);
SalesLine.VALIDATE(Type,SalesLine.Type::Item);
SalesLine.VALIDATE("No.",Item."No.");
SalesLine.MODIFY(TRUE);
SalesLine.SETRANGE("Document Type",SalesHeader."Document Type");
SalesLine.SETRANGE("Document No.",SalesHeader."No.");
IF SalesLine.FINDLAST THEN
NextLineNo := SalesLine."Line No.";
NextLineNo += 10000;
SalesLine."Line No." := NextLineNo;
Quantity := 5;
SalesLine.Quantity := Quantity;
SalesLine."Quantity (Base)":= SalesLine.Quantity;
SalesLine."Qty. to Invoice" := SalesLine.Quantity;
SalesLine."Qty. to Invoice (Base)" := SalesLine.Quantity;
SalesLine."Qty. to Ship" := SalesLine.Quantity;
SalesLine."Qty. to Ship (Base)" := SalesLine.Quantity;
SalesLine."Gen. Prod. Posting Group" := 'RETAIL';
SalesLine."Gen. Bus. Posting Group" := 'DOMESTIC';
SalesLine."VAT Bus. Posting Group" := '';
SalesLine."VAT Prod. Posting Group" := '';
SalesLine."VAT Calculation Type" := SalesLine."VAT Calculation Type"::"Reverse Charge VAT";
//End;
SalesLine.MODIFY(TRUE);
CODEUNIT.RUN(CODEUNIT::"Sales-Post",SalesHeader);
Thanks,
Mani
0 -
Hi @ManiNav
If you go to docs you can read more about C/AL:
https://docs.microsoft.com/en-us/dynamics-nav/c-al-repetitive-statements
There are a lot of help to find.For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.0 -
hai Maninav please find this
saleslinerec.INIT;
saleslinerec."Document Type" := saleslinerec."Document Type"::Order;
saleslinerec."Document No." := '86000' ;
saleslinerec.VALIDATE("Sell-to Customer No.",'01121212');
saleslinerec."Line No." := 86001;
saleslinerec."Shipment Date" := 120519D;
saleslinerec.Quantity := 102;
saleslinerec."Unit of Measure" :='kgs';
saleslinerec.Amount :=10000;
saleslinerec.Type := saleslinerec.Type::Item;
saleslinerec."No." :='70063';
saleslinerec.VALIDATE("No.",'70063');
saleslinerec.MODIFY ;
}
salesline2rec.INIT;
salesline2rec."Document Type" := salesline2rec."Document Type"::Order;
salesline2rec."Document No." :='86000';
salesline2rec.VALIDATE("Sell-to Customer No.",'01121212');
salesline2rec."Line No." := 86002;
salesline2rec."Shipment Date" := 120519D;
salesline2rec.Quantity := 122;
salesline2rec."Unit of Measure" :='kgs';
salesline2rec.Amount :=1000;
salesline2rec.Type := saleslinerec.Type::Item;
salesline2rec."No." :='70064';
salesline2rec.VALIDATE("No.",'70064');
salesline2rec."Location Code" :='YELLOW';
salesline2rec.INSERT ;0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions