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....');
Hey just to be sure:
The Primary Key for Table Purchase Line is: "Document Type,Document No.,Line No."
Where did you set the "Document Type" ?
Normaly I would expect PurchaseLine."Document Type" := PurchaseHeader."Document Type";
Kind Regards
That would be the first catch , Fill in the Primary Key for Purchase Line as well and then check.
You will need below 2 lines to work.
PurchaseLine.INIT;
purchaseline."document type" := Purchaseheader.document type;
purchaseline."document no." := purchaseheader."no."
PurchaseLine."Line No.":=REQLine."Line No."+1000;
Alemayehu Ayele said:PurchaseHeader."Document Type" := "Document Type"::Order;
I can't see the line like PurchaseLine."Document Type" := PurchaseHeader."Document Type";I think you have a lot of Quotes now :)
Alemayehu Ayele said:PurchaseLine.INIT; PurchaseLine."Line No.":=REQLine."Line No."+1000; PurchaseLine."Document No.":= PurchaseHeader."No.";
You must define the document type in your purchase line.
PurchaseLine."Document Type" :- PurchaseLine."Document Type"::Order;