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 AX (Archived)

orig() value in POST event

(0) ShareShare
ReportReport
Posted on by

Hi!,

I asked similar question before but not exactly the same...

The previous answer didnt summerise whole topic...

In my project i have to compare value that was change in table... and after change i have to log the action i another table...

E.G.

Table AAA field BBB changed from "ccc" to "ddd" my POST event handle the action and put the log into another table...

Table AAA contain also field XXX and if XXX is changed event do nothing...

Is it possible to handle that only in POST event ??

In PRE i have ability to use orig() and compare what was changed... but in POST orig() doesnt work ;/

Thank you in advance!

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    For reference, the "previous answer" probably is in Class name which cause the event or Table operation name.

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Consider using database logging - it can detect changes for you and give the old and new values, so you can focus on your actual business logic instead of reinventing the infrastructure.

    It's too late asking for orig() after the change is already done.

  • Community Member Profile Picture
    on at

    Hmm i don't understand how to solve it...

    I asked if that situation is possible to solve in POST event... Is there any way to look at the previous values of field ??

    Maybe i have to handle it in PRE... pass Arg throught .addArgs() to POST... and finish handle it in POST ??

    Im also affraid to addAgrs() because MSN cautions about that activity...

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    As I said, it's too late trying to get values from orig() - that makes sense only before doing the update.

    Using things like addArgs() would lead to very bad code, difficult to work with and prone to errors (missing compile-time control and so on). Adding a line of code via overlayering is a much better one from these two alternatives.

    Of course, you can still consider my previous suggestion with database logging.

  • Community Member Profile Picture
    on at

    Perhaps i have to little knowledge :) Because i don't even noticed that you suggested something :)

    1) Database Logging... could you explain a little bit ?? reference to my e.g. ??

    2) What do you mean by overlayering ??

    I understand that orig() is possible... thats why i asked you :) In many languages e.g. C# there is access to NEW and OLD value in PRE and POST event... I'm suprised that X++ did support it only in PRE event...

  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    You can always find documentation using a search engine. Here is an introduction: TechNet: Configure and manage database logging.

    Overlayering allows you to change existing code. For example, table AAA is defined on layer VAR and you want to add some code to update() method. You open the development environment in your development layer (such as CUS), find table AAA and start changing it, such as adding code to update(). You changes are stored in your layer (CUS in this case) and they take precedence over the original code in VAR.

    I'm surprised that you do X++ development and you've never heard about layers and overlayering. It seems that you've missed some basics of AX development; fortunately there is documentation to help you, such as Modify Objects in the Standard Application.

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Your understand of orig() is wrong. It's a copy of the table buffer at the point when you read it from database; it has nothing to do with events. In the moment when you put your changes from the buffer to database, the value in DB (orig()) and your buffer become identical. You seem to be looking for "value that used to be current in database before last changes", but that's not the purpose of orig(). orig() returns the last known value in database.

  • Community Member Profile Picture
    on at

    That overlayering i understood... never use but know :)

    But completly dont know how to use this in my case... :) didnt se the connection with overlayering and POST event with OLD value :)

    I also know that orig() is bad solution because it is made for another purpose... i put the orig() as prompt to the usability which i want to achive...

    Summarize... How to create orig()'similar function which will be working handle POST event...

  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    You should spend some time looking at existing code, if you have no AX developer to teach you the basics. You'll see that overlayering is used everywhere, especially because event handlers didn't even exist in older versions.

    Dealing with orig() is also a common pattern - I'm can find a plenty of examples if the standard application (cross-references would help you with it). For example, this is how you can handle update() of AAA.

    public void update()
    {
        // Remember previous values before calling updating database
        AAA orig = this.orig();
    
        // Do the update
        super();
    
        // Call some code, pass both the current and the previous values
        MyLogger::log(this, orig);
    }

    Sometimes it's enough handling things before super (e.g. if (this.Field1 != this.orig().Field1)) and depending on transaction rollback if the update fails.

  • Community Member Profile Picture
    on at

    Now i get it :)

    I forget that PRE/POST i could do manually by puting code BEFORE/AFTER super()...

    I wanted to create clear solution... that i have generic event handler class which can handle every table... then i could easily add the event to tables insert/update/delete and fouse only on specific implementation for entities...

    Approach with BEFORE/AFTER super() will be harder to maintain because i have to change code in many places instead of one generic handler...

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 AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans