Hi All,
I'm using the following codes to change one of Comment Line Key but I realized some records are deleted (insert was failed)
.
my intention is that I want to rename number comment line by using insert-delete method. Is there any better way?
CommentLine.RESET;
CommentLine.SETRANGE("No.",'XXX');
IF CommentLine.FINDSET THEN BEGIN
REPEAT
CommentLine2.INIT;
CommentLine2.TRANSFERFIELDS(CommentLine);
CommentLine2."No." := 'ZZZ';
CommentLine2.INSERT;
CommentLine.DELETE;
UNTIL CommentLine.NEXT = 0;
END;
Answers
Commentline.RENAME(newvalkeyfield1,newvalkeyfield2)
(Findset(true, true))
Use RENAME is slower and hit error 'Not allowed to rename' for some tables. Is there better way to use INSERT-DELETE method?
Insert your New records from temp table. Repeat the procedure Per 100 records if you have lots of data in the table. Deleteall and Commit per 100 records if possible. Or do IT per item/customer or whatever you can use as point of return. Fill tour temp table again wil the next bulk of records. Empty tour temp table each time.
CommentLine.RESET;
CommentLine.SETRANGE("No.",'XXX');
IF CommentLine.FINDSET THEN BEGIN
REPEAT
TempCommentLine.DELETEALL;
TempCommentLine.INIT;
TempCommentLine.TRANSFERFIELDS(CommentLine);
TempCommentLine."No." := 'ZZZ';
TempCommentLine.INSERT;
IF TempCommentLine.FINDFIRST THEN BEGIN
CommentLine2.INIT;
CommentLine2 := TempCommentLine;
CommentLine2.INSERT;
CommentLine.DELETE;
END
UNTIL CommentLine.NEXT = 0;
END;
CommentLine.SETRANGE("No.",'XXX');
IF CommentLine.FINDSET THEN BEGIN
REPEAT
TempCommentLine.INIT;
TempCommentLine.TRANSFERFIELDS(CommentLine);
TempCommentLine."No." := 'ZZZ';
TempCommentLine.INSERT
UNTIL CommentLine.next <= 0;
Commentline.deleteall;
TempCommentLine.findset;
Repeat
CommentLine.TRANSFERFIELDS(tempCommentLine);
CommentLine.insert;
UNTIL TempCommentLine.next <= 0;
Faster or not at all. Just give it a try.