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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Can I override a table event handler if table itself has extension?

(0) ShareShare
ReportReport
Posted on by

Hi 

I created a extension (CustTable.Extension) to table "CustTable" to add more fields.  

Then I would like to override onModifiedField event handler so I created a class "CustTable_Extension" and copy/paste the onModifiedField event handler and modified to the following:

[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(CustTable), DataEventType::ModifiedField)]
public static void CustTable_onModifiedField(Common sender, DataEventArgs e)
{
    ModifyFieldEventArgs event = e as DataEventArgs;
    CustTable custTable = sender as CustTable;
    FieldId fieldId = event.parmFieldId();

    switch(fieldId)
    {
        case fieldNum(CustTable, ContactPersonId):

            <Adding business logic here>

            break;

        default:
            break;
    }

}

}

It's simple customization for event handler but somehow this piece of code is never executed even when I modified "ContactPersonId".  I am wondering whether or not create customized event handler for the table when there is another table extension to add new fields is NOT supported?  If so, what could be workaround?

I have the same question (0)
  • Suggested answer
    Sukrut Parab Profile Picture
    71,735 Moderator on at

    Hi Yvonne,

    You should not add event handlers to extension class . below link explains it well why

    daxmusings.codecrib.com/.../accidental-code-extensions.html

    You can just implement your handler in a normal class with proper naming convention . for example MyCusttableHandler class

    Now for your another question , you  can use COC on table  modified field method instead of using event handler. That would be the first place i would look at , if you want something on modified event of the field.

  • Community Member Profile Picture
    on at

    Hi Sukrut,

    Does this mean override table event handler only work when there is no other table extension at all (no table extension on the table level for adding fields or table extension on class level to override methods)?

    Thanks,

    Lin-Lin

  • Community Member Profile Picture
    on at

    It seems writing COC on "modifiedField" method does not work either.  The code compiled code never get to the breakpoint set in there even the field is modified.  It works for the table without any extension to add fields, so are these the current limitations of extension?

  • Sukrut Parab Profile Picture
    71,735 Moderator on at

    I am not aware of any limitation . If you are sure , you are writing code at correct place and executing correct process which will trigger that code then breakpoint should hit.

  • Suggested answer
    Khushhal Garg Profile Picture
    1,514 on at

    I am using OnModifiedField eventhandler and it is working fine. I have created public class and have added following method and it is working fine.

       [DataEventHandler(tableStr(VendTable), DataEventType::ModifiedField)]

       public static void VendTable_onModifiedField(Common sender, DataEventArgs e)

       {

           VendTable record = sender as VendTable;

           ModifyFieldEventArgs args = e as ModifyFieldEventArgs;

           FieldId fieldId = args.parmFieldId();

    I am seeing you are using    

    ModifyFieldEventArgs event = e as DataEventArgs;

    instead of

    ModifyFieldEventArgs args = e as ModifyFieldEventArgs;

    that might be the issue. Can you change your code also to

    ModifyFieldEventArgs args = e as ModifyFieldEventArgs;

    and move event handler to public class from final class?

  • Blue Wang Profile Picture
    Microsoft Employee on at

    Hi Yvonne,

    I don't think it's a good way to use event handlers in extensions.

    Of course, you can achieve your needs, and this is the previous method.

    You can refer to this thread:

    [View:https://community.dynamics.com/ax/f/microsoft-dynamics-ax-forum/217518/using-pre-post-event-handlers-on-modifiedfield-method-of-a-table-in-case-of-customization:750:50]

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    There can be many extensions for the same object, and many event handlers for the same event.

    As pointed out above, it seems that your issue might happen because you are using incorrect DataEventArgs type instead of ModifyFieldEventArgs.

    You should not add event handlers to extension classes. Instead you should create separate event handler classes that don't extend any other class.

    By the way, you should not name your extensions like CustTable.Extension (or classes like CustTable_Extension), instead you should include your prefix in the name. Otherwise you might have issues / conflicts in the future when applying Microsoft updates.

  • Community Member Profile Picture
    on at

    I found out the issue is ContactPersonId on CustTable cannot trigger onModifiedField event as the field is being set by editContactPerson() method on the data source.  For any other fields that are directly mapped to CustTable fields will not have problem.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 659

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 465 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 304 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans