var // Local var SalesLine: record "Sales Line"; SalesHeader: record "Sales Header"; ReleasesSalesLine: record "Sales Line"; LineCount: Integer; SalesOrderList: Text; begin LineCount := 0; // Find all sales lines with the item on SalesLine.SETRANGE("Document Type", 1); SalesLine.SETRANGE(Type, SalesLine.Type::Item); SalesLine.SetFilter("No.", '= %1', SourceItemNo); IF SalesLine.FINDSET(TRUE) THEN REPEAT SalesHeader.Get(SalesLine."Document Type", SalesLine."Document No."); SalesLine.Validate("No.", NewItemNo); // Change item no and validate SalesOrderList += SalesLine."Document No." + ' Line: ' + Format(SalesLine."Line No.") + '\'; SalesLine.MODIFY(TRUE); LineCount := LineCount + 1; // Update line count var UNTIL SalesLine.NEXT = 0; Message('Done ' + '\' + SalesOrderList); end;
Answers
Try this one
IF SalesLine.FINDSET(TRUE) THEN
REPEAT
SalesHeader.Get(SalesLine."Document Type", SalesLine."Document No.");
LastState := SalesHeader.Status; //LastState - integer
SalesHeader.Status := SalesHeader.Status::Open ; //Don't use VALIDATE
SalesHeader.MODIFY; //Don't run MODIFY trigger
SalesLine.Validate("No.", NewItemNo); // Change item no and validate
SalesOrderList += SalesLine."Document No." + ' Line: ' + Format(SalesLine."Line No.") + '\';
SalesLine.MODIFY(TRUE);
SalesHeader.Status := LastState;
SalesHeader.MODIFY;
LineCount := LineCount + 1; // Update line count var
UNTIL SalesLine.NEXT = 0;
But best way:
1. reopen Sales Order using CU 414 "Release Sales Document" function Reopen
2. Release Sales Order after Line modification using same CU
An implicit conversion is being performed from a value of type 'Enum "Sales Document Status"' to a value of type 'Integer'. This conversion can lead to unexpected runtime issues. This warning will become an error in a future release.
Fixed by using this:
LastState: Enum "Sales Comment Document Type";