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

Call a Form method from FormDataFieldEventHandler

(0) ShareShare
ReportReport
Posted on by

Hi,

I am customizing InventTransferOrders Form. I want to initialize few fields based on newly created custom field.

I want to call form method 'updateItemId()' to run the logic for initializing ItemId field. I created the event handler of 'onModified()' method. I have initialized the FormRun object and trying to call form methods from it but I cannot see the method. 

Can you please help me how I can call form methods and variables in event handler?

Thanks in advance!

Regards,

Sohagani Shah

*This post is locked for comments

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

    You should be able to get formRun as below and then called method using formrun object

    FormRun formRun = sender.formRun() as FormRun;  

    formRun.myCustomMethod()

    // Get the selected datasource record    TableName tableBuffer = sender.cursor();  

    // Get datasource variable     FormDataSource DSVariable = sender.formRun().dataSource(“TableName”); }

    even if you don't see method in IntelliSense try to build it and see if you are getting any error.

  • Verified answer
    Basheer17 Profile Picture
    2,720 on at

    Usually we don't get IntelliSense for any additional methods other than base(FormRun) methods in the eventhandlers  using FormRun object. You can simply hard code the method and it will be called in the run time.  

  • André Arnaud de Calavon Profile Picture
    303,728 Super User 2026 Season 1 on at

    Hi Sohagani,

    Can you explain in detail what you are doing? Where and how did you create new fields? What is the relation between these fields and calling the method you have mentioned? Do you have other additional logic or requirements?

  • Prabakaran.R Profile Picture
    313 on at

    Hi,

    In  I am using form data field event handler. here how can i call data source methods and form methods inside that field event handler method. please suggest me

    /// <summary>

    ///

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    [FormDataFieldEventHandler(formDataFieldStr(PurchTable, PurchLine, itemBarCode), FormDataFieldEventType::Modified)]

    public static void itemBarCode_OnModified(FormDataObject sender, FormDataFieldEventArgs e)

    {

         FormDataSource purchLine_ds = sender.datasource();

        PurchLine purchLine = purchLine_ds.cursor();

    }

    Thanks,

  • Penny Song Profile Picture
    22 on at

    Hi Sohagani,

    Maybe you have found solution . But I hope this can help others.

    [FormDataFieldEventHandler(formDataFieldStr(PurchTable, PurchLine, itemBarCode), FormDataFieldEventType::Modified)]
    
    public static void itemBarCode_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    
    {
    
         FormDataSource purchLine_ds = sender.datasource();
    
        PurchLine purchLine = purchLine_ds.cursor();
        
        FormRun formRun =   purchLine_ds.formRun();
        if(formHasMethod(formRun,formMethodStr(PurchTable,updateItemId))
        
        {
        
            formRun.updateItemId();
        
        }
    
    }

  • Suggested answer
    Volodymyr Pavlovskyi Profile Picture
    65 on at

    Please note that this is a Type conversion approach, there you are declaring FormRun and calling a method which actually does not exist on a FormRun object, to overcome this and write a nice code you can change declaration of your form, for example:

    public class CustomForm extends FormRun implements CustomFormClassImplement

    And then create an instance of a class CustomFormClassImplementand call a method from this class.

    CustomFormClassImplement customFormClassImplement = purchLine_ds.formRun();

    customFormClassImplement.UpdateItemId() ,

    Although it is a bit harder with a standard forms as you cannot change form declaration. But still possible by extending some class(if exists)

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans