create sales order with multiple line using cal/code

Hi Everyone,

I am trying to create sales order with multiple line using cal/code. I am able to create SO with single line, so please help me , to create multiple lines ie in looping of more than one item[If i want to add item: 1000(Bicycle), and 1001(Touring Bicycle)...]

Here is my code:

Item.INIT;
Item."No." :=  'Bicycle';


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." :='2010';
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);

Thanks in advance.

mani

Related
Recommended