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
0
Answers
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,
Mani
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
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.
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 ;