Hi Experts!
I have four records in a table. These records are numbered: 1, 2, 3 and 4. These numbers are in a primary key-field of a table.
I have also a form, and with this form it is possible to modify these 1-4 fields. What kind of code do I have to write, if I want a functionality like this: When number is changed from 1 to 4, the other number 4 is changed automaticly to 1 and when number is changed from 2 to 3, the other number 3 is changed automaticly to 2 etc.?
************
Mr. Nice Guy
************
0
Comments
SETRANGE("Order No.", "Order No.");
IF FINDFIRST THEN
"Order No." := xRec."Order No.";
Name := xRec.Name;
Code := xRec.Code;
..but I didn't succes. Can you give me an example code?
************
Mr. Nice Guy
************
RIS Plus, LLC
But your desire is very odd and weird.
Why when renaming one record would you ever want to rename another one and which one ? how do you know that 1 corresponds to 4; that 2 corresponds to 3 ?
when you try to rename record 1 to 4 then the record 4 has to be renamed to 1 but this will cause circular/recursive OnRename trigger calls and you have to stop the recursion somehow.
So, if its not necessary store this information in an other field. Because after rename all "Subtables" with Relations must also changed.
If u must use this field as PK, and must rename, then do this per separate function and use insert and delete. Its faster. But you need for this process an Buffer variable (to store old information before delete)
a) Rename record 1 to XXX
b) Rename record 3 to 1
c) Rename record XXX to 3
else you have the conflict that the record already exists...
2) What about just transfering (exchanging) the rest of the record? But this depens on if the records in another tables are refering this table and if you need to correct the reference too... than you really need to rename.
3) Or you can delete/re-insert the record, but again, linked fields will not be updated
4) Or you can find another solution which do not need to rename - e.g. do not use the number as PK, use something else as PK and use this no. just as another field...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
My task was only to make sure that user don't choose same number twice. The thing, why I tried to use this field as a PK-field based on idea that in that case the modified records in a table would automaticly get in order 1, 2, 3 and 4. Anyway thanks for your advice I now understand the solution I was planning was too complicated to carry out.
Maybe OK-button and under this button a code, where the unequality of numbers is checked. If someone of you have a good hint of how to do such a verification thanks on beforehand.
************
Mr. Nice Guy
************
2) You can use No. Series to assign some code automatically
3) You can use GUID datatype and function for generating the guid to generate unique value for each record.
4) etc...
It depends on how the PK is used in other processes...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.