OnModify no executed when OnRename

I notice that if I modify some fields in a record and then (no move between records) I rename the record, the OnRename trigger is executed but OnModify don’t. Is this a bug?

When you run the Modify(True)then system will run the Table Modify trigger, but on Rename you do not have a choice for running or not running the trigger (You only pass the primary key values). Since program modify the primary key in the OnRename you are not allowed to ignore the onRename trigger. Its by Design. Naveen Jain

Hi, I agree with Naveen. OnRename is fired implicitly whenever you change the primary key of a record, where as you have to call the OnModify trigger explicitly by passing TRUE as parameter. Best Regards

From Jesús description, it sounds as if he is using a Form and not C/AL code…

You’re right Nelson, it happens when modifying the record in a form not from C/AL.

I guess a rename in fact is a deletion of the old record and an insertion of new (a copy of the old with the primary key changed). Therefore it does not (in Navision terms) constitute a modification and thus the OnModify trigger is never called.

What about the code you write in the OnModify trigger to assure data integrity? I think that before the system calls the OnRename it must check if any other field has been changed, in this case, it must call the OnModify and then continue with the OnRename. As a simple example: - The OnModify trigger on Customer Table has the following code ... IF (Name <> xRec.Name) OR ("Search Name" <> xRec."Search Name") OR ("Name 2" <> xRec."Name 2") OR ... THEN BEGIN MODIFY; UpdateContFromCust.OnModify(Rec); END; ... If in the customer card you modify the Name and then (remember not move from record) the No. you get the customer modified (no OnModify Trigger gets executed) but your Contact card does not reflect the change.

Jesus (no pun intended), That’s one helluva (pardon my french) good observation! This, in fact, is quite a serious problem in the whole application [:0] I don’t know how often this actually occurs in real life, but I guess Murphy was an optimist [8D]

One more “Special observation”. In a Cronus DB test this, - Go to Countries Form - Push button: Country / VAT. Reg. No. Format - Push: Show All (or clear all filters) >>> You can see all VAT formats for all countries - GoBack to Countries Form - Create a new country > - Country Code: * > - … - Delete the new created Country - Try now the first three steps > You have no VAT formats This happens with any value that could be interpreted as a filter. How many SETFILTERS like this one in all application or customizations? Sometimes SETFILTER(, ‘%1’, ) can avoid the problem (Test country code like “N…Z”) So use SETRANGE, when possible. Anyway, as you said Steffen,


I don’t know how often this actually occurs in real life, but I guess Murphy was an optimist

If you really think that “this never happens”, have a look at http://www.navision.net/forum/topic.asp?TOPIC_ID=11208