I am having a hard time finding a automated way to rename the customer No. and having it cascade the changes down through the other tables that the Customer No. is written in. (i.e. the sales invoice header, etc.) Has anyone had to do this? If so could you share the solution.
David E. Revell
Comments
The RENAME function should work:
RENAME (Record)
Use this function to change a primary key in a C/SIDE table.
RENAME will select the best key (index) available when renaming linked records.
Regards,
Bruno
Bruno
http://blogs.ittoolbox.com/erp/smb
I think, It is important to add that the cascade rename works only for the fields with proper TableRelation property set.
Customer.RENAME(Customer."No.");
and it doesn't rename the Customer No's
Hi,
first you should locate the record you would like to rename. Then provide a new value(s) of primary key field(s) to the RENAME command. The example could be:
Cust.GET('10000');
Cust.RENAME('123456');
...or...
Cust.FIND('-');
Cust.RENAME('NEW' + Cust."No.");
But! This would not work:
Cust."No." := 'NEW' + Cust."No.";
Cust.RENAME(Cust."No.");
Thanks in advance for the help
David Revell
be careful doing that. You can easily create a neverending loop if you use the primary key. Try to save the original customer nos into a new field, than create a new key on this field. Than use the newly created key to renumber the records. I had some problems when i was renumbering fixed assets.
--
János Borsics
So something like this:
Customer
"OnAfterGetRecord"
VarCust := Customer;
varCust.No := NoSeriesMgt.GetNextNo(NoSeriesCode, SeriesDate, ModifySeries)
varcust.rename(varcust.no);
"Customer No. Old" := "No.";
SalesSetup.GET;
CLEAR(NewNo);
NoSeriesMgt.InitSeries(SalesSetup."Customer Nos.",SalesSetup."Customer Nos.",0D,NewNo,SalesSetup."Customer Nos.");
RENAME(NewNo);
Variables
Name DataType Subtype Length
NoSeriesMgt Codeunit NoSeriesManagement
SalesSetup Record Sales & Receivables Setup
NewNo Code 20
1. Don't get the salessetup every time. Do it on PreDataItem, the code is not going to change.
2. NoSeriesMgt.InitSeries calls NoSeriesMgt.GetNextNo so you don't need that. Do a "varCust.No := NoSeriesMgt.GetNextNo(salessetup.NoSeriesCode, 0d, true);"
3. As rename cascades through all values that link to Customer.No it is always going to be slow. So if you need to do it in a limited amount of time, you'll have to split the job using filters.