Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Get Form datasource method in class extension

Posted on by Microsoft Employee

Hi All,

How to get the form datasource method in modified eventhandler in class extension.

Please help me.

Thanks for your valuable reply.

  • Suggested answer
    Prabakaran.R Profile Picture
    Prabakaran.R 305 on at
    RE: Get Form datasource method in class extension

    Hi Arun,

    You can use like that,

    [FormDataFieldEventHandler(formDataFieldStr(InventTransferOrders, InventTransferLine, QtyTransfer), FormDataFieldEventType::Modified)]
    public static void QtyTransfer_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    {

    FormDataSource inventTransferLine_ds = sender.datasource();

    InventTransferLine inventTransferLine = inventTransferLine_ds.cursor();

    inventTransferLine .initvalue();

    }

    Thanks,

    Prabakaran R.

  • Suggested answer
    Sukrut Parab Profile Picture
    Sukrut Parab 71,643 Moderator on at
    RE: Get Form datasource method in class extension

    try this

    FormRun formRun = _sender.datasource().formRun();

    FormDataSource ForecastSales_ds = = formRun.dataSource(ForecastSales')

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get Form datasource method in class extension

    In First line also i m getting error:

    i just wrote the two lines of code.

  • Sukrut Parab Profile Picture
    Sukrut Parab 71,643 Moderator on at
    RE: Get Form datasource method in class extension

    which line you are getting this error ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get Form datasource method in class extension

    Thanks for reply.

    Its throw error to me.

    This is my scenario:

    FormDataFieldEventHandler(formDataFieldStr(ForecastSales, ForecastSales, Currency), FormDataFieldEventType::Modified)]

       public static void Currency_OnModified(FormDataObject sender, FormDataFieldEventArgs e)

       {

         FormDataSource ForecastSales_ds =

         sender.datasource(formDataSourceStr(ForecastSales, ForecastSales));

         ForecastSales_ds.updateAmount();

        }

    its throw error FormDataObject.datasource,expect 0 arguments,but 1 specified

  • Sukrut Parab Profile Picture
    Sukrut Parab 71,643 Moderator on at
    RE: Get Form datasource method in class extension

    once you get the datasource just put datasource_ds.yourMethodname() . It doesn't show your method when you indent  but it works

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get Form datasource method in class extension

    Hi Sukrut,

    Thanks for your reply.

    I already tried your suggestion but i cant able to call the datasource method.

    please help.

    Thanks

    Arun Joseph A

  • Sukrut Parab Profile Picture
    Sukrut Parab 71,643 Moderator on at
    RE: Get Form datasource method in class extension

    Answer is already given . Did you check my reply ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get Form datasource method in class extension

    D 365

  • Suggested answer
    Sukrut Parab Profile Picture
    Sukrut Parab 71,643 Moderator on at
    RE: Get Form datasource method in class extension

    You can get formDatasource from sender as shown below

    FormDataSource projTable_ds = sender.formRun().dataSource("ProjTable");

    another way is

    FormDataSource MyRandomTable_ds = sender.dataSource(formDataSourceStr(SomeForm, MyRandomTableDS)

    Once you have formDatasource you can easily access its methods.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,835 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans