Renaming a customer no.

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.

Field: Name

Table: Customer

It is possible to change the primary key of any table like customer number only if you have developer license not with the customer license.

I hope it helps

Hi,

Why dont you copy the first to second and Delete the first…

  1. 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.

  2. The account has ledger entries and I want them to follow to the new account. Would be a pain to redo all of it.

Anyone else have any ideas?

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.

I would not change the primary key.

Hi,

Use ‘Copy’ function.

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.

It is described on MSDN: https://msdn.microsoft.com/en-us/library/dd301056(v=nav.90).aspx

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:

GET(‘30000’) fails.

Hi Jeson,

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.

I tried that and it did not, but thank you.

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 :slight_smile: So I don’t know which one is breaking it.

Hi Jason,

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.

Here is a video by Waldo that explains how to use the debugger in NAV 2013->

When running the debugger, then it will show you exactly in which code the error happens.

My own guess is that it related to customizations done to the system. But a programming error it is.

But please let us know what was the cause, if you find it.

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.

Turn on Code Coverage. It won’t give you the answer, but it will show you all the objects involved.

Turn on Code Coverage. It won’t show where the error comes from but it will list all the objects involved.

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?

I will give that a shot. Thanks.

I just tried that and code coverage didn’t help.