Modifing a primary key value...

deepblue
Member Posts: 152
Hello!
I would like to modify the value of a field which belongs to the primary key of a record. When I try to use MODIFY, error message appears saying that the record NewValue does not exist. How can I do it?
Thank You!
I would like to modify the value of a field which belongs to the primary key of a record. When I try to use MODIFY, error message appears saying that the record NewValue does not exist. How can I do it?
Thank You!
0
Answers
-
Try
rec.GET(primarykeyfield1,primarykeyfield2,..)
rec.RENAME(PrimaryKeyfield1NewValue,PrimaryKeyfield2NewValue,..)0 -
I'm trying to modify many records, but RENAME only works for the first record! ](*,)
WITH Record1 DO BEGIN RESET; SETRANGE(Field1,'Exemple'); SETRANGE(Field2,0); if FIND('-') then REPEAT RENAME(Field1,NewField2,Field3); UNTIL NEXT = 0; END;
0 -
deepblue wrote:I'm trying to modify many records, but RENAME only works for the first record! ](*,)
WITH Record1 DO BEGIN RESET; SETRANGE(Field1,'Exemple'); SETRANGE(Field2,0); if FIND('-') then REPEAT RENAME(Field1,NewField2,Field3); UNTIL NEXT = 0; END;
Try this instead:Rec1.reset; Rec1.setrange(field1,'exemple') ; Rec1.setrange(field2,0) ; if Rec1.find('-') then repeat Rec2 := Rec1 ; Rec2.rename( field1, newfield2, field3 ) ; until Rec1.next = 0 ;
0 -
Strange. It should work. However, I assume that renaming is not a part of your standard business process but a one-time only correction, you could write code with filevar.CREATE, filevar.TEXTMODE(TRUE),filevar.WRITE('text'); to generate hardcoded code to a textfile and copy-paste it into Navision, generating code like:
CLEAR(Record);
Record.GET('B112');
Record.RENAME('A134');
Ugly, but it works as a one-time solution.0 -
0
-
Looks like you are trying to insert more then 1 record with the same Primary key. If you have 3 fields in the primary key then based on your code you have to change value of the Field3 before RENAME.Best Regards,
Oleg0
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