I am trying to change a customer number from say 1200 to 1201. 1201 is not in the system, so it is a “new” number. It goes through table by table and then fails saying the Name needs to be a part of the key(primary) for the customer table. If I change the primary key on the customer table to No.,Name instead of the default No., it works. But I really don’t like doing that. Also I’ve been doing this in a test database.
From what I’ve been reading is sounds like another table is linked back to the customer table, I assume the name field, and that is why it is having problems. I’m having a hard time tracking down what table. I’ve looked at all modified tables for a flowfield reference to No. or Name. I’ve recored the screen to see if I could see the table it was trying to work on before the error pops up. I’ve traced the DB through SQL and haven’t got anywhere. Am I doing something wrong or looking for the wrong thing? Thanks for your help.
Jason
The Error
The field below must be included in the table’s primary key.
I do not have a developer license and I can still change the primary key. I do have the application builder licence. And that is an option, but not the best solution.
The account has ledger entries and I want them to follow to the new account. Would be a pain to redo all of it.
Look for TableRelation property that refers to Customer.Name. This exception is thrown when there is a relation to a field not belonging to the primary key.
I wouldn’t consider changing the primary key in the “Customer” table as an option at all, it is a destructive change. Just one example. Customer is often read from the database by calling Customer.GET(%SomeCustomerNo%). If your primary consists of two fields, this “GET” will look for a customer with No. = %SomCustomerNo%, and blank name. A lot of code won’t work anymore because it won’t be able to find the customer record.
The GET would return the first occurrence of that “No.” in the table. It would not fail. Of course that might not be the record you want, so yes some code might fail.
GET doesn’t look for the first record in the table matching a partial key, it requires exact match of all key fields. When called on a table with compound primary key, all omitted values are assumed to be blank.
As an example take any table with compound primary key (e.g. Vendor Invoice Disc. - it has vendor no., currency code and minimum amount in the key) and call with only one value in the parameters.
I created an invoice discount for vendor 30000 with blank currency and minimum amount = 0:
Now GET(‘30000’) returns this record successfully.
When I rename the record to include some other values in the primary key like this:
This error can be from a customized code so, before you rename the customer No., start the debugger. Then rename the No. It’ll show where the error comes from.
Do you mean look at the tablerelation in the customer table or the one that is creating the problem? If you mean the one creating the problem…that is what I’m trying to find So I don’t know which one is breaking it.
Yes try to turn on the Debugger from the Development Environment, or the classic client. Btw. which version is this on? If it’s on NAV 2009 RTC then the debugger will not work. But then try to rename from the classic client instead of RTC.
I’m using NAV 5sp1, so even older. I tried turning the debugger on, like I normally do when I’m tracking down issues, but the message comes up and the debugger shows nothing.
This whole process of cascade updates including the exception you see is handled by the platform, so C/AL debugger or code coverage won’t catch it.
I suggest looking at tables that have references to customer. It should be the one creating the problem. Probably it could be found from object metadata. If it’s NAV 5, maybe Developer’s Toolkit could help? Have you tried importing all your objects into NDT and running “Where Used” on Customer.Name?