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 :
Finance | Project Operations, Human Resources, ...
Answered

Extending a form datasource field

(0) ShareShare
ReportReport
Posted on by 213

Hi

I am trying to add a modified method on the VendGroup field on the VendTable form (when changed it should update a custom field of mine).  I have tried in two different ways and both have failed!  I would very much appreciate someone letting me know which way is "best" and what I have done wrong!

Many thanks in advance

Try 1

[ExtensionOf(formDataFieldStr(VendTable, VendTable, VendGroup))]
final class VendTable_VendGroup_Extension
{

    public void modified()
    {
        #define.blank('')

        next modified();

        // When group changes, subgroup should be cleared
        VendTable.myNewSubGroupField = #blank;

        // Refresh Vendor data source
        VendTable_ds.refresh();

    }

}

Try 2

[ExtensionOf(formStr(VendTable))]
final class VendTable_Extension
{
    [FormDataFieldEventHandler(formDataFieldStr(VendTable, VendTable, VendGroup), FormDataFieldEventType::Modified)]
    public static void VendGroup_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    {
        #define.blank('')

        super();

        // When group changes, subgroup should be cleared
        VendTable.myNewSubGroupField = #blank;

        // Refresh Vendor data source
        VendTable_ds.refresh();
    }

}

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    The first one should work, just don't call refresh of the data source.

    The second one should not even compile, and you mix event handlers and Chain of Command, effectively adding a method called VendGroup_OnModified to VendTable form.

  • André Arnaud de Calavon Profile Picture
    301,194 Super User 2025 Season 2 on at

    Hi Chris,

    I do agree with Nikolaos. Don't use the refresh.

    I would like make another note. You are now using a macro for the empty value. In Dynamics 365, you can now use the keyword 'const' like in C#. It has multiple advantages which you can read in the next blog: (+) X++ in AX7: Const keyword - Dynamics 365 Finance Community

  • cjohnson300 Profile Picture
    213 on at

    Thanks André and Nikolaos

    My first block of code doesn't compile and states "The qualifier 'VendTable' is not valid in this context.  Use a variable of this type instead"?

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Try this:

    public void modified()
        {
            #define.blank('')
            VendTable vendTableLocal = element.VendTable;
    
            next modified();
    
            // When group changes, subgroup should be cleared
            vendTableLocal.myNewSubGroupField = #blank;
    
        }

    UPDATE: removed the .refresh() call, since you should not have it.

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,194 Super User 2025 Season 2 on at

    Hi Chris,

    If you get an error that VendTable is not recognized, you have to ensure you have the correct model references added on your extension model.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 467 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans