I would like tom get your opinion on these testing

Using the tables on the file attached, could you test and give opinion on these examples

First setup Change Log for the tables and all fields

Testing OnRename Trigger

  1. Open Table Test_1
  2. Insert record with values: KeyField = 1, DataField = ‘A’ (press TAB to insert the record)
  3. Go to the record and move to field DataField
  4. Modify record typing as follows: Data = ‘AAAA’ (press Shift+TAB), Key = 100 (press TAB and select Yes to rename the record)

You will get the message on the trigger as follows

xRec: 1 AAAA
Rec: 100 AAAA

NOTES

  1. xRec must say 1 A instead on 1 AAA
  2. If you have a look on Table 405 Chanhge Log Entry you will see it saves the right values

You can try this on table Test_2 as follows

  1. with no filters at all (it works OK)
  2. with a fixed filter (not range nor expression) in one of the KeyFields (the same result as in table Test_1 when you change the KeyField with no filter)

Testing DELETE (F4)

  1. Open table Test_2
  2. Insert record with values: KeyField_1 = 1, KeyField_2 = 1, DataField = ‘A’
  3. Insert record with values: KeyField_1 = 2, KeyField_2 = 1, DataField = ‘B’ (press TAB to insert the record)
  4. Go to second record
  5. Type in KeyField_1: 1, press F4 and select Yes to delete the record

The record that remains in the DataBase is 2,1,B

If you have a look on Table 405 Chanhge Log Entry you will see it saves as deleted the record 1, 1, B (never saved to the DataBase)

One more question on this, when writing code in OnDelete trigger, should we use Rec or xRec when testing values to allow deletion?

Thanks in advance for your opinions

Hi,

Not sure what the purpose of your post is. Are you having some problems writting code or do you need some help with Testing?

T

Hi,

I disagree with the behaviour of Navision in these examples, so I ask your opinion about that.

Do you think is ok that Rename give you some data (xRec vs Rec) in trigger and saves other thing to Change Log ?

  • I think Change Log data is ok, so how can you validate the record info to decide to continue with Rename?

And, what about to delete a record that is no the one you have selected? I am now talking from “user” point of view.

Thanks,

Pretty interesting tests. I didn’t know that the content of xRec was dependent of the trigger.

To answer you question, you should rec on the OnDelete trigger as it is the primary keys from rec that is used to delete the record and not primary keys xRec (the record you actually changed).

Regards

Claus

Hi Claus,

About your answer, if you use Rec to validate that the record can be deleted, if you changed the fields on the primary key, you are not testing with the right Data.

Let’s say,

Record 1: KeyField_1= 1, KeyField_2=1, DataField=A

Record 2: KeyField_1=2, KeyField_2=1, DataField=B

Record OnDelete Trigger: IF DataField=‘A’ Error(‘Cannot delete’)

Try the following,

Try to delete record 1 using F4 and you will get the error from the trigger.

Change record 2: KeyField_1=1 and press F4 and deletes the record with Key (1,1) that cannot be deleted if you look the trigger.

Regards

In my opinion xRec is wrong in the OnRename trigger (and also validate triggers – you get a similarly result), however xRec has the correct values in the OnModify trigger.

Regards

Claus

Hi again Claus,

xRec on the OnValidate is ok, you have the records that your are modifying,

xRec has your modifications up to before the field you are validating

Rec includes all your changes, including the field you are validating

This is different in OnModify, OnDelete, xRec is the original record you read, and Rec includes all your changes, and this is what I think you must get on the OnRename trigger (an it really is, except in the case I was testing).

Regards

I was assuming you wanted to test the record based on the primary key fields. I guess your test shows that you need to re-get the record on the OnDelete trigger to perform test on non-primary key fields or check that the primary key fields haven’t been changed. I find this behavior a bit odd and I think we can agree that this is a bug in Navision.

Regards

Claus

I guess it can be discussed if xRec is wrong or not in the OnValidate triggers. I just find it a bid odd that xRec is different dependent on the trigger (change two non-primary fields and compare xRec between the last changed field and the OnModify – different, why?).

Anyway as long as you know how it works, you can program around it.

Regards

Claus

Definitely the values of xRec int he OnRename trigger do not seem to be what you would expect. Especially when you consider that they are differnt depending on weather you call the trigger in code (MyRecord.RENAME(TRUE):wink: or by manually entering somethign in the field. I was recently in asituation where renaming the primary key in one record required renaming another record, and the code worked differntly depending on where the user triggered the code.

I worked around it, and it works fine, but I do think it is at least “An Undocumented Feature”, if not maybe a bug.