RENAME BY USING INSERT/DELETE

Angelo
Member Posts: 180
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;
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;
0
Answers
-
If no. is part of primary key
Commentline.RENAME(newvalkeyfield1,newvalkeyfield2)
(Findset(true, true))0 -
Hi TallyHo,
Use RENAME is slower and hit error 'Not allowed to rename' for some tables. Is there better way to use INSERT-DELETE method?0 -
You can try to use a temp table.
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.0 -
Is this what you mean?
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;0 -
CommentLine.RESET;
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions