Rename records on tables

bekio
Member Posts: 204
Hello everyone,
I want to rename records on Product Group table, field code(that is part of primary key), and i can not do it. I have made a codeunit with code:
ProductGroup.RESET;
ProductGroup.INIT;
IF ProductGroup.FINDFIRST THEN
REPEAT
ProductGroup.Code:= ProductGroup."Item Category Code" +'/' +ProductGroup.Code;
ProductGroup.MODIFY;
UNTIL ProductGroup.NEXT=0;
But when i execute it it stops on the firs record displaying a error:
The Product Group does not exist.
Identification fields and values:
Item Category Code= xxx, Code= xxx/yyy;
Any suggestion how to do this, with function because i have a lot of records there.
Thanks in advice!
:!:
I want to rename records on Product Group table, field code(that is part of primary key), and i can not do it. I have made a codeunit with code:
ProductGroup.RESET;
ProductGroup.INIT;
IF ProductGroup.FINDFIRST THEN
REPEAT
ProductGroup.Code:= ProductGroup."Item Category Code" +'/' +ProductGroup.Code;
ProductGroup.MODIFY;
UNTIL ProductGroup.NEXT=0;
But when i execute it it stops on the firs record displaying a error:
The Product Group does not exist.
Identification fields and values:
Item Category Code= xxx, Code= xxx/yyy;
Any suggestion how to do this, with function because i have a lot of records there.
Thanks in advice!
:!:
0
Answers
-
You cannot use MODIFY command to modify a primary key fields.
Instead use RENAME.
See the code below;
ProductGroup.RESET;
IF ProductGroup.FINDFIRST THEN
REPEAT
if ProductGroup2.get(ProductGroup."Item Category Code",ProductGroup.Code) then
ProductGroup2.Rename("Item Category Code",ProductGroup."Item Category Code" +'/' +ProductGroup.Code);
UNTIL ProductGroup.NEXT=00 -
FelixAntony wrote:You cannot use MODIFY command to modify a primary key fields.
Instead use RENAME.
See the code below;
ProductGroup.RESET;
IF ProductGroup.FINDFIRST THEN
REPEAT
if ProductGroup2.get(ProductGroup."Item Category Code",ProductGroup.Code) then
ProductGroup2.Rename("Item Category Code",ProductGroup."Item Category Code" +'/' +ProductGroup.Code);
UNTIL ProductGroup.NEXT=0
Improper use of FINDFIRST. Also why fetch records twice?ProductGroup.RESET; IF ProductGroup.FINDSET THEN REPEAT ProductGroup2 := ProductGroup; ProductGroup2.Rename("Item Category Code",ProductGroup."Item Category Code" +'/' +ProductGroup.Code); UNTIL ProductGroup.NEXT=0
There are no bugs - only undocumented features.0 -
thanks bbrown!
=D>0 -
how do take care of
IF FINDSET RENAME() UNTIL NEXT = 0
where primary key contains multiple fields and you are renaming field number 4 for example?
in my example working with 'analysis view entry'SETRANGE("Dimension 2 Value Code",'12345');
IF FINDSET THEN
REPEAT
i := i+1;
IF "Dimension 4 Value Code" = '' THEN
RENAME("Analysis View Code","G/L Account No.","Dimension 1 Value Code","Dimension 2 Value Code",
"Dimension 3 Value Code",'11111',"Business Unit Code","Posting Date","Entry No.");
UNTIL NEXT = 0;
it seems like after the rename it fails to find the next record due to resort?Microsoft Certified Technology Specialist
Microsoft Certified Business Management Solutions Professional
Microsoft Certified Business Management Solutions Specialist
http://www.navisiontech.com0 -
That's why you don't rename using the record variable with which you are reading thru the table.There are no bugs - only undocumented features.1
-
ahhh, i should have actually read the code. :thumbsup:Microsoft Certified Technology Specialist
Microsoft Certified Business Management Solutions Professional
Microsoft Certified Business Management Solutions Specialist
http://www.navisiontech.com0
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