I have been working on some code to create purchase orders from service orders. But I am getting stuck when trying to do multiple items. If anyone would have some pointers I would appreciate it. I am sure I am not doing something right on finding all records in the service lines.
here is my code on a single.
IF Type = Type::Item THEN BEGIN
WITH NewPurchLine DO BEGIN
INIT;
"Document No." := PurchNo;
"Document Type" := "Document Type"::Order;
IF LineNo = 0 THEN
LineNo := 10000;
"Line No." := LineNo;
INSERT(TRUE);
VALIDATE(Type,Type::Item);
VALIDATE("No.",Item."No.");
VALIDATE(Quantity,parServLine.Quantity);
VALIDATE("Unit Cost",parServLine."Unit Cost");
VALIDATE("Unit of Measure Code",parServLine."Unit of Measure Code");
MODIFY;
LineNo := LineNo +1;
END;
END;
vs multiple
IF Type = Type::Item THEN BEGIN
WITH NewPurchLine DO BEGIN
ServiceLine.RESET;
ServiceLine.SETRANGE(ServiceLine."No.", "Document No.");
IF ServiceLine.Findset THEN REPEAT
INIT;
"Document No." := PurchNo;
"Document Type" := "Document Type"::Order;
IF LineNo = 0 THEN
LineNo := 10000;
"Line No." := LineNo;
INSERT(TRUE);
VALIDATE(Type,Type::Item);
VALIDATE("No.",Item."No.");
VALIDATE(Quantity,parServLine.Quantity);
VALIDATE("Unit Cost",parServLine."Unit Cost");
VALIDATE("Unit of Measure Code",parServLine."Unit of Measure Code");
MODIFY;
LineNo := LineNo +1;
UNTIL ServiceLine.NEXT = 0;
END;
END;
*This post is locked for comments