RENAME statement comes up with strange key field name
                
                    groover                
                
                    Member Posts: 31                
            
                        
            
                    Has anybody seen a message like this:
The field below must be included in the table's primary key:
Field: Description
Table: Item
The error pops up when I try to rename an Item, even if the item is completely new and has no related entries (ledger entries, sales lines, translations, vendors, ...) at all.
The exact code is:
                The field below must be included in the table's primary key:
Field: Description
Table: Item
The error pops up when I try to rename an Item, even if the item is completely new and has no related entries (ledger entries, sales lines, translations, vendors, ...) at all.
The exact code is:
recItem2.RENAME("Search Description");
It is part of a small customization to replace the Item No. by a unique Search Description. But why would it come up with the "Description" field???                BR,
Groover
Groover
0                
            Comments
- 
            It should be something likeItem.GET('1000'); Item.RENAME(Item."Search Description");
 This works fine.
 Beware of the fact that "Search Description" is 30 characters long, also it is modified then the description is modified.0
- 
            Well, in fact I DO a:recItem2.GET 
 before doing the RENAME. When debugging it breaks on the line with the RENAME statement, which makes me think that it has something to do with the RENAME function itself and the way it uses keys. What I simply don't understand is why it wants the "Description" field to appear in the Primary Key... In version 3.01 it works, in version 4.00 it doesn't work anymore...BR,
 Groover0
- 
            And more:
 1. The OnValidate trigger of the Description field has been modified so that the Search Description is no longer changed when the description is changed.
 2. The error occurs even with a clean Item record (with NO related entries at all).
 3. If I open the 301 database in 400, it still works.
 4. If I dump my 4.00 form into the 301 database, it still works.
 5. If I use this code in a completely new company, it works too...
 ==> Is this data related then?BR,
 Groover0
- 
            Is there some strange tablerelation in the item description or search description field?0
- 
            No. The TableRelation property contains the default value <Undefined> for both fields...BR,
 Groover0
- 
            And the "No." field? Any strange tablerelations?0
- 
            NoBR,
 Groover0
- 
            groover wrote:The field below must be included in the table's primary key:
 Field: Description
 Table: Item
 This error message is shown when you make a tablerelation with a non-primairy key field of a table.
 Somewhere in your database, there has to be a field with a tablerelation Item.Description
 The Rename function triggers all related fields to be changed.
 Export all tables to a textfile and search this.0
- 
            OK. Found it. It was indeed a very weird piece of customization. It was a normal field, with Editable=No, and with a Conditional TableRelation referring to the Item.Description field. Strange, because it was never used. I reckon the badly designed field was initially meant to be a FlowField of the "Lookup" type. I have cleaned up the mess.
 Many thanks for the advice, Mark!!!BR,
 Groover0
- 
            Guys you are looking in the wrong place.....
 The ONLY time that you would use RENAME is when you need to change the primary key of a record. For example:Item.GET('10000'); Item."No." := '20000'; Item.RENAME;This will work because the "No." field is the primary key of the Item table. You can also do:SalesLine.GET(SalesLine."Document Type"::Order,'1234',10000); SalesLine."Line No." := 20000; SalesLine.RENAME; This will work, because the "Line No." field is part of the primary key of the Sales Line table.
 This, however:Item.GET('10000'); Item.RENAME(Item."Search Description");Will not work, because the search description is not part of the primary key. If you need to modify any other field that is not the primary key, you do this:Item.GET('10000'); Item.VALIDATE("Search Description",'NEWVALUE'); Item.MODIFY(TRUE);You don't need to use RENAME, because you're not modifying primary key values.0
- 
            Hi Daniel.
 Problem is solved.
 You were 3 minutes to late 
 I had to dig realy deep in my memory, but I knew I saw this message before.0
- 
            Cool, I'm happy the problem is solved. I just felt the need to elaborate a little, because there was mention of exact code:recItem2.RENAME("Search Description");and that is just not correct.
 Good to know though that in RENAME there can also be issues with table relations, I have not seen that before.0
- 
            RENAME will update all table related fields, exept when the renamed table is shared over all companies. 
 Whenever consultants test new versions of my add on it is one of the first things they do, to test the tablerelations.0
- 
            Hi Daniel,
 Your last piece of code actually DOES work. And the intention of the code WAS/IS to change the primary key. The syntax of is correctItem.RENAME(Item."Search Description"); but you have to be aware, as Mark said, that Search Description can be 30 characters, and that it is normally changed when Description is changed!!! Thanks for the advice, to both of you!DenSter wrote:Guys you are looking in the wrong place.....
 The ONLY time that you would use RENAME is when you need to change the primary key of a record. For example:Item.GET('10000'); Item."No." := '20000'; Item.RENAME;This will work because the "No." field is the primary key of the Item table. You can also do:SalesLine.GET(SalesLine."Document Type"::Order,'1234',10000); SalesLine."Line No." := 20000; SalesLine.RENAME; This will work, because the "Line No." field is part of the primary key of the Sales Line table.
 This, however:Item.GET('10000'); Item.RENAME(Item."Search Description"); Will not work, because the search description is not part of the primary key. If you need to modify any other field that is not the primary key, you do this:Item.GET('10000'); Item.VALIDATE("Search Description",'NEWVALUE'); Item.MODIFY(TRUE);You don't need to use RENAME, because you're not modifying primary key values.BR,
 Groover0
- 
            Maybe I misunderstood what you want to do.Item.RENAME(Item."Search Description"); This line of code will change the primary key value of the record in the Item variable with the current value of the "Search Description" field as the new value of the primary key. If that is what you want it to do, then yes it works (of course taking into account the fieldlength issue).
 I thought you wanted to change the value of the "Search Description" field. Maybe it was me who was looking in the wrong place afte all. Wouldn't be the first time, and certainly won't be the last 8)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
- 323 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

