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 Microsoft Employee

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

  • Suggested answer
    RE: Call a Form method from FormDataFieldEventHandler

    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)

  • Penny Song Profile Picture
    Penny Song 22 on at
    RE: Call a Form method from FormDataFieldEventHandler

    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();
        
        }
    
    }

  • Prabakaran.R Profile Picture
    Prabakaran.R 307 on at
    RE: Call a Form method from FormDataFieldEventHandler

    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,

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,516 Super User 2025 Season 1 on at
    RE: Call a Form method from FormDataFieldEventHandler

    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?

  • Verified answer
    Basheer17 Profile Picture
    Basheer17 2,720 on at
    RE: Call a Form method from FormDataFieldEventHandler

    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.  

  • Verified answer
    Sukrut Parab Profile Picture
    Sukrut Parab 71,680 Moderator on at
    RE: Call a Form method from FormDataFieldEventHandler

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans