web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

OnBeforeModifyEvent - xRec

(0) ShareShare
ReportReport
Posted on by 714

Hi Team,

    I would like to check with you regarding "OnBeforeModifyEvent - xRec". I can see the xRec.xxx (previous value) if we change the value from table or page. But xRec.xxx value is always same as current record modified value if we modifed by code. Does is standard behavior or bug?

NAV - 2016 CU14 (AU)

Regards,

Yukon

*This post is locked for comments

I have the same question (0)
  • Luc van Vugt Profile Picture
    on at

    [quote user="Yukon"]But xRec.xxx value is always same as current record modified value if we modifed by code.[/quote]

    Yep, if you have done it by using an assignment statement, i.e. Rec.Field := NewValue;

    However, if you dit program Rec. VALIDATE(Field,NewValue) xRec.Field contains previous value.

    See also https://dynamicsuser.net/nav/b/vanvugt/posts/validating-data-2-using-validate-c-tnd

  • Yukon Profile Picture
    714 on at

    Dear Luc,

           Thanks for your reply and share the information. After I read your blog and reproduce the code as per your blog but still result is same.

    Here is sample

    PurchOrderPlanningBuffer.GET(0);

    PurchOrderPlanningBuffer.VALIDATE("Item Description",'New');

    PurchOrderPlanningBuffer.MODIFY;

    Same as your example - 1 (xRec value is different with Rec value)

    OnBeforeModifyEvent.png

     

    Here is onBeforeModify Event.

    OnBeforeModifyEvent.png

    OnBeforeModifyEvent2.png

     

    Regards,

    Yukon

  • Luc van Vugt Profile Picture
    on at

    Great you tested it, as I hadn't. ;-) And I hadn't come across it yet. Sounds like a bug to me.

  • Yukon Profile Picture
    714 on at

    Yes, I think same as you but haven't test on other CU and 2017. Let see other member reply.

    Regards,

    Yukon

  • Community Member Profile Picture
    on at

    It's the same on 2017.

    If I remember right, it's only if you modify by code.

  • Luc van Vugt Profile Picture
    on at

    Thanx, Dennis.

    Yukon, if you want I can report it to MS as MVP.

  • Yukon Profile Picture
    714 on at

    Thanks, Luc. Please report it to MS. Nowadays, we are star using Event.

    Regards,

    Yukon

  • Suggested answer
    Community Member Profile Picture
    on at

    It looks a little bit strange, but if you write in event xRec.GET before your code everything be as you expecting

  • Luc van Vugt Profile Picture
    on at

    No, Nikolay, that's not strange as the record in the table has not been modified yet, so a GET on that record will give you the old (=current) version.

  • Luc van Vugt Profile Picture
    on at

    Hi guys, I have just checked it in NAV 2017 and works fine, so xRec is different from Rec. For both OnBeforeModifyEvent and OnAfterModifyEvent.

    I have tested with the following code:

    OBJECT Codeunit 88889 Update Item

    {

     OBJECT-PROPERTIES

     {

       Date=16-06-17;

       Time=09:16:42;

       Version List=OnBeforeModifyEvent - xRec;

     }

     PROPERTIES

     {

       OnRun=BEGIN

               UpdateDescriptionAssigment;

               UpdateDescriptionValidate;

             END;

     }

     CODE

     {

       VAR

         Item@1000 : Record 27;

       LOCAL PROCEDURE UpdateDescriptionAssigment@1();

       BEGIN

         WITH Item DO BEGIN

           GET('1000');

           Description := 'Bicycle UpdateDescriptionAssigment';

           VALIDATE(Description);

         END

       END;

       LOCAL PROCEDURE UpdateDescriptionValidate@2();

       BEGIN

         WITH Item DO BEGIN

           GET('1000');

           VALIDATE(Description,'Bicycle UpdateDescriptionValidate');

         END

       END;

       BEGIN

       END.

     }

    }

    OBJECT Codeunit 88888 Item - Events

    {

     OBJECT-PROPERTIES

     {

       Date=16-06-17;

       Time=08:42:12;

       Version List=OnBeforeModifyEvent - xRec;

     }

     PROPERTIES

     {

       OnRun=BEGIN

             END;

     }

     CODE

     {

       [EventSubscriber(Table,27,OnBeforeValidateEvent,Description)]

       LOCAL PROCEDURE BeforeOnValidateDescription@1(VAR Rec@1000 : Record 27;VAR xRec@1001 : Record 27;CurrFieldNo@1002 : Integer);

       BEGIN

         MESSAGE('BeforeOnValidateDescription')

       END;

       [EventSubscriber(Table,27,OnAfterValidateEvent,Description)]

       LOCAL PROCEDURE AfterOnValidateDescription@2(VAR Rec@1000 : Record 27;VAR xRec@1001 : Record 27;CurrFieldNo@1002 : Integer);

       BEGIN

         MESSAGE('AfterOnValidateDescription')

       END;

       BEGIN

       END.

     }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans