Record copy to Another table

Hi Guys I was trying to copy the requisition record to the Purchase order table. But when I run the code it only adds a record to the purchase header but not to the purchase line. Any clue I missed in my code. Thanks in advance.

REQLine.RESET;
REQLine.SETRANGE(REQLine."Document Type","Document Type");
REQLine.SETRANGE(REQLine."Requistion No","No.");
IF REQLine.FINDFIRST THEN BEGIN
PurchaseHeader.INIT;
PurchaseHeader."No.":='';
PurchaseHeader.Status := Status::Open;
PurchaseHeader."Purchase Requisition No." := "No.";
PurchaseHeader."Document Type" := "Document Type"::Order;
PurchaseHeader."Assigned User ID" := USERID;
PurchaseHeader."Posting Date" := TODAY;
PurchaseHeader."Buy-from Vendor No." := '';
PurchaseHeader."Document Date" := TODAY;
PurchaseHeader.INSERT(TRUE);
REPEAT
PurchaseLine.INIT;
PurchaseLine."Line No.":=REQLine."Line No."+1000;
PurchaseLine."Document No.":= PurchaseHeader."No.";
PurchaseLine.Type := ReqLine.Type;
PurchaseLine."No." := ReqLine."No.";
PurchaseLine.Quantity := ReqLine."Quantity Requested";
PurchaseLine."Unit of Measure Code" := ReqLine."Unit of Measure";
PurchaseLine.INSERT();
UNTIL REQLine.NEXT=0;
MODIFY;
COMMIT;
PurchaseHeader.SETRANGE("No.");
MESSAGE('Purchase Order No. %1 created.',PurchaseHeader."No.");
PAGE.RUN(50, PurchaseHeader);
END
ELSE
ERROR('Something wrong....');

Parents
No Data
Reply Children
No Data
Related
Recommended