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)

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,710 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
    301,095 Super User 2025 Season 2 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

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