XRec Values = rec Values in Modify Trigger

jens_DEBERjens_DEBER Member Posts: 3
edited 2014-07-30 in NAV Three Tier
Hi,

it seem i have found a bug with the XRec. Please confirm me or correct me. :D
Vendor.INSERT(TRUE);
Vendor.Name := 'Name 1';
Vendor.MODIFY(TRUE);
After this piece of Code in the Vendor - OnModify - Trigger xRec.Name is equal to Rec.Name. Is that correct or do I something wrong? Should it be so?

I tested in NAV2013 (7.0.36347) and NAV2013R2 (7.10.35473)

Best Regards Jens

Comments

  • pdjpdj Member Posts: 637
    If you need to trust xRec, you need to get it your self.
    Just insert a xRec.FIND('=') in the beginning of the OnModify trigger.
    Regards
    Peter
  • brunellibrunelli Member Posts: 9
    Hi Jens

    This is expected beheavior. See online help:
    http://msdn.microsoft.com/en-us/library ... 9(v=nav.70).aspx

    pdj's solution is one way to solve the issue, but it could lead to unexpected beheavior depending on the following code and from where the trigger is called from other objects.

    Further links:
    http://dynamicsuser.net/forums/p/12614/61225.aspx
    viewtopic.php?t=27859&f=23
    viewtopic.php?f=23&t=41483&start=0
    http://dynamicsuser.net/blogs/vanvugt/a ... ports.aspx

    Best,

    B.
  • serdarulutasserdarulutas Member Posts: 47
    I read somewhere that it is the behavior when the validation doesn't come from the form that bounds to the table. One workaround would be creating a custom OnModify(xrec) function and do your xrec vs rec validations in there.

    So in
    1. So your table's onModify trigger would call the custom OnModify(xrec) function when it needs comparison implicitly
    2. And when xrec happens to be same as rec when it actually should not, you can call the Table.OnModify(xrec) function externally in your code by using a temp rec.
  • moriccellimoriccelli Member Posts: 6
    i've just met the issue and understood, that there are two events: OnBeforeModifyEvent, OnAfterModifyEvent (My problem appeared in subscriptions). So on OnAfterModifyEvent the situation is just like you described - the xRec is fully same with Rec. But on OnBeforeModifyEvent - everything is just on place. You would see xRec.Name as `''` and Rec.Name as `Name 1`

    If you really want to check the changes use the subscriptions and OnBeforeModifyEvent. Tested on NAV2018
  • JuhlJuhl Member Posts: 706
    As i remember, the OnBefore is only working from Page. If change come from code you have to use a GET to get xRec.
    Follow me on my blog juhl.blog
  • moriccellimoriccelli Member Posts: 6
    I have checked all the scenarios - from code and from page in NAV18 works fine...
Sign In or Register to comment.