Behaviour of xRec

ta5ta5 Member Posts: 1,164
Hi
I have some code on a Table.OnModify trigger. When modifying is done from a form, everything works fine.
However, if the modify trigger is called like "table.modify(true)", rec and xrec in the onmodify trigger are the same.

Is this be design?

Many thanks in advance
Thomas

Comments

  • krikikriki Member, Moderator Posts: 9,112
    It is not a bug, it just works like that.
    I know it is anoying but that is the way it works.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    You can have a look at table 5050 where there is a workaround. This table has a OnModify function that you can call from code as wel.

    What you should do is before changing the table store the xrec in a variable. After the modify you can call the function with the new and old record variable.
  • ta5ta5 Member Posts: 1,164
    Thanks for your info about that :)
  • klumklum Member Posts: 102
    Hi,

    Table 5050 is very usefully. I just clear about xrec now too :)

    Best Regards,
    Klum
  • prussellprussell Member Posts: 1
    There is a sever limitation to the way this is handled in table 5050.

    When you implement this using a PARAMETER called xRec, then the User-Defined-Function (not the trigger) called OnModify can reference this parameter, but any function called inside the UDF will still be referencing the (incorrect) xRec.

    For Example


    OnModify() //trigger
    OnModify(xRec)

    OnModify(xRec : Record Contact) //user defined function. this work around is shown on table 5050
    IF xRec.Name <> Name THEN
    MESSAGE('This xRec reference works correctly');
    SubFunction();

    SubFunct() //sub functions using xRec DO NOT WORK with this workaround, because the PARAMETER xRec is never passed to them!
    IF xRec.Name = Name THEN
    MESSAGE('This xRec reference incorrectly references the same thing as Rec');
Sign In or Register to comment.