When I change the quantity of a line item on a PO in my code unit, it updates the Qty to Receive of all lines while it only updates the particular line when I do it on a form.
IF RecPurchaseLine.Quantity <> OrderedQty THEN BEGIN
// WHEN ORDERED QTY IS GREATER THAN ORDER QTY THEN UPDATE THE ORDERED QTY
RecPurchaseLine.VALIDATE(RecPurchaseLine.Quantity, OrderedQty);
RecPurchaseLine.MODIFY;
IF DocumentType = 'Order' THEN BEGIN
// record initialisation
RecPurchaseHeader.INIT;
RecPurchaseLine.INIT;
// filtering header record
RecPurchaseHeader.SETFILTER("No.",DocumentNo);
RecPurchaseHeader.SETFILTER("Document Type", 'Order');
// filtering line items
RecPurchaseLine.SETRANGE("Document Type", RecPurchaseLine."Document Type"::Order);
RecPurchaseLine.SETFILTER("Document No.",DocumentNo);
RecPurchaseLine.SETFILTER("Line No.",'<>0');
RecPurchaseLine.SETFILTER("No.",ItemNo);
//if rows exists
IF RecPurchaseLine.COUNT>0 THEN BEGIN
REPEAT
IF RecPurchaseLine."No." = ItemNo THEN BEGIN
IF RecPurchaseLine.Quantity <> OrderedQty THEN BEGIN
// WHEN ORDERED QTY IS GREATER THAN ORDER QTY THEN UPDATE THE ORDERED QTY
RecPurchaseLine.VALIDATE(RecPurchaseLine.Quantity, OrderedQty);
RecPurchaseLine.MODIFY;
// to clear the receivedQty
ClearReceivedQty(DocumentType,DocumentNo,ItemNo);
END;
MaxReceivableQty := RecPurchaseLine.Quantity - RecPurchaseLine."Quantity Received";
NewReceivedQty := RecPurchaseLine."Qty. to Receive" + QtyToReceive;
IF MaxReceivableQty >= NewReceivedQty THEN BEGIN
RecPurchaseLine.VALIDATE (RecPurchaseLine."Qty. to Receive" ,NewReceivedQty); // Validate n update field value
RecPurchaseLine.MODIFY; // modify record set.
COMMIT;
EXIT;
END;
END;
// clearing the calculated fields for line
Clear(MaxReceivableQty);
Clear(NewReceivedQty);
UNTIL RecPurchaseLine.NEXT = 0;
END
ELSE
IF RecPurchaseLine.COUNT = 0 THEN BEGIN
// ADD NEW LINE ITEM ON SALES ORDER
RecPurchaseLine.RESET;
RecPurchaseLine.SETRANGE(RecPurchaseLine."Document No.", DocumentNo);
CLEAR(NextLineNo);
IF RecPurchaseLine.FIND('+') THEN BEGIN
NextLineNo := ROUND(RecPurchaseLine."Line No.",1000,'=')+10000;
END
ELSE BEGIN
NextLineNo := 10000;
END;
RecPurchaseLine.INIT; // INITIALISE PURCHASE LINE
RecPurchaseLine.VALIDATE (RecPurchaseLine."Document Type", RecPurchaseLine."Document Type"::Order);
RecPurchaseLine.VALIDATE ("Document No.", DocumentNo);
RecPurchaseLine."Line No." := NextLineNo;
RecPurchaseLine.VALIDATE (Type, RecPurchaseLine.Type::Item);
RecPurchaseLine.VALIDATE ("No.", ItemNo);
RecPurchaseLine.VALIDATE (Quantity,OrderedQty);
RecPurchaseLine.VALIDATE ("Qty. to Receive",QtyToReceive);
RecPurchaseLine.INSERT;
COMMIT;
END;
END;
ProcessPoToReceipt(VAR DocumentNo : Text[50];VAR DocumentType : Text[30]) RetMsg : Text[1000]
IF DocumentType = 'Order' THEN BEGIN
RecPurchaseHeader.SETFILTER("No.",DocumentNo);
RecPurchaseHeader.SETFILTER("Document Type",DocumentType);
RecPurchaseHeader.INIT;
IF RecPurchaseHeader.FIND('-') THEN BEGIN
RecPurchaseHeader.Receive := TRUE; // SETTING PROPERTY TO RECEIVE
RecPurchaseHeader.Invoice := FALSE;
IF cuPurchPost.RUN(RecPurchaseHeader) THEN BEGIN
MESSAGE('processed');
RetMsg := 'Receipt Created Successfully';
END
ELSE BEGIN
error(GETLASTERRORTEXT);
RetMsg := GETLASTERRORTEXT;
END;
END;
END;
ClearReceivedQty(VAR DocumentNo : Text[50];VAR DocumentType : Text[30];VAR ItemNo : Code[50])
IF DocumentType = 'Order' THEN BEGIN
RecPurchaseHeader.INIT;
RecPurchaseLine.INIT;
// filtering header record
RecPurchaseHeader.SETFILTER("No.",DocumentNo);
RecPurchaseHeader.SETFILTER("Document Type", 'Order');
// filtering line items
RecPurchaseLine.SETFILTER("Document No.",DocumentNo);
RecPurchaseLine.SETFILTER("Document Type", 'Order');
RecPurchaseLine.SETFILTER("Line No.",'<>0');
IF STRLEN(ITEMNO) > 0 THEN BEGIN
RecPurchaseLine.SETFILTER("No.",ItemNo);
END;
IF RecPurchaseLine.FINDSET THEN BEGIN
//if rows exists
IF RecPurchaseLine.COUNT>0 THEN BEGIN
REPEAT
IF RecPurchaseLine."Qty. to Receive" > 0 THEN BEGIN
RecPurchaseLine.VALIDATE ("Qty. to Receive" ,0); // Validate n update field value
RecPurchaseLine.MODIFY; // modify record set.
COMMIT;
END;
UNTIL RecPurchaseLine.NEXT = 0;
END;
END;
END;
I dont think its to do with looping over the lines as I separated the change QTY method and called it for each line.
When I validate it, it modifies the qty to receieve ](*,)
PS You should try not to use the COUNT function as it doesn't perform very well. Use NOT ISEMPTY or FIND('-') or FINDSET (depending on your version) instead
Answers
Code is like this (line is filtered already).
regards,
Could you post some more code plz? How do you set the filters? Do you loop over the lines in some way?
When I validate it, it modifies the qty to receieve ](*,)
PS You should try not to use the COUNT function as it doesn't perform very well. Use NOT ISEMPTY or FIND('-') or FINDSET (depending on your version) instead
Thanks for your help and looking into my messy code
regards,