Loading...

Form Control Event Handler Methods in Dynamics 365

Form Control Event Handler Methods in Dynamics 365

 For example, In Dynamics 365 for Operations you can react to the OnClicked event by copying the event handler method for the event and pasting the method into a class. 


Below is an example of an event handler method that reacts to the OnClicked event of a button on a form.



Create new Class and paste below code in it for SalesEditLines EventHandlers

 /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(SalesEditLines, OK), FormControlEventType::Clicked)]
    public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        Args args = new Args();
        FormCommandButtonControl  callerButton = sender as FormCommandButtonControl;  //Retrieves the button that we're reacting to
        FormRun form = callerButton.formRun(); //Gets the running SalesEditLines form

        //Get the salesId that was selected in the SalesEditLines form
        FormDataSource salesParmTable_ds = form.dataSource(formDataSourceStr(SalesEditLines, SalesParmTable)) as FormDataSource;
        SalesParmTable salesParmTable = salesParmTable_ds.cursor();


        SalesTable salesTable=salesParmTable.salesTable();

        if(salesTable.SalesStatus==SalesStatus::Invoiced)
        {
     
//Any Action

        }
    }

Reference

Reference



Another Sample for OnModified of check box control - AllowEdit  text box control based on checkbox selection




 /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(EcoResProductDetailsExtended, Other_CatchWeight), FormControlEventType::Modified)]
    public static void Other_CatchWeight_OnModified(FormControl sender, FormControlEventArgs e)
    {
        FormCheckBoxControl  callerButton = sender as FormCheckBoxControl ;  //Retrieves the button that we're reacting to
        FormRun element = callerButton.formRun();
        FormControl catchweightMultipleToSubProject = element.design(0).controlName("Other_CatchweightMultiple");
        if(callerButton.checked())
        {
            catchweightMultipleToSubProject.allowEdit(true);
        }
        else
        {
            catchweightMultipleToSubProject.allowEdit(false);
        }
    }


On Look Up Event for String Control in the form

 [FormControlEventHandler(formControlStr(VendBankAccounts, PartyPaymLocationName), FormControlEventType::Lookup)]
    public static void PartyPaymLocationName_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        FormControl   callerStr = sender as FormControl;  //Retrieves the string that we're reacting to
        FormRun form = callerStr.formRun(); //Gets the running VendBankAccounts form

        FormDataSource vendBankAccount_ds = form.dataSource(formDataSourceStr(VendBankAccounts, VendBankAccount)) as FormDataSource;
        VendBankAccount vendBankAccount = vendBankAccount_ds.cursor();

        vendBankAccount.vendPartyPaymLookup(callerStr );
 

    }

Creating License Plate at Item Arrival line creation while Enter non-existing Liecense Plate



 public static void InventoryDimensionsGrid_LicensePlateId_OnEnter(FormControl sender, FormControlEventArgs e)
    {
            FormControl   callerStr = sender as FormControl;  //Retrieves the string that we're reacting to
            FormRun form = callerStr.formRun(); //Gets the running  form

            FormStringControl InventoryDimensionsGrid_LicensePlateId = form.design(0).controlName("InventoryDimensionsGrid_LicensePlateId");

            if(InventoryDimensionsGrid_LicensePlateId.text())
            {
                WHSLicensePlate::createLicensePlate(InventoryDimensionsGrid_LicensePlateId.text());
            }
    }

Assign or SET value to Form string control 

 [FormControlEventHandler(formControlStr(InventJournalTransferReceive, InventDimIssue_InventBatchId), FormControlEventType::Modified)]
    public static void InventDimIssue_InventBatchId_OnModified(FormControl sender, FormControlEventArgs e)
    {

        FormControl   callerStr = sender as FormControl;  //Retrieves the string that we're reacting to
        FormRun form = callerStr.formRun(); 
     
//   FormDataSource dsInventJournalTrans = sender.formRun().dataSource("InventJournalTrans");

     
        FormStringControl InventJournalTrans_PurchId = form.design(0).controlName("InventJournalTrans_PurchId");
     
        
     
               InventJournalTrans_PurchId.enabled(true);

                //True parameter append the text but false removes existing text and paste new text

                InventJournalTrans_PurchId.pasteText("SET TEXT HERE",FALSE);
                InventJournalTrans_PurchId.enabled(false);

              
            }
        }
    }

Published on:

Learn more
Sherif Fayed
Sherif Fayed

Share post:

Related posts

20 Most Commonly Used JavaScript Scenarios with Sample Code Snippets in Form Script – Dataverse / Dynamics 365 CE

JavaScript plays a critical role in Microsoft Dataverse and Dynamics 365 Customer Engagement (CE) applications. While Power Automate and Busin...

4 days ago

Dynamics 365 CE and Power Platform Developer Syllabus

Extensive & Advanced Syllabus for Power Platform & Dynamics 365 CE If you want to become an expert in Microsoft Power Platform and Dyn...

5 days ago

From Campaign Automation to Agentic Marketing: The Next Phase of Microsoft Dynamics 365 Customer Engagement

As organizations evaluate Microsoft Dynamics 365 Customer Insights capabilities, a common question keeps emerging: Are we still designing camp...

12 days ago

Dynamics 365 CE 2026 Release Wave 1 Launch Event Webinar

Western Computer recently hosted a launch event walking through Dynamics 365 CE 2026 Release Wave 1, focused on what's changing across Sales, ...

16 days ago

Microsoft Copilot in Dynamics 365 Customer Engagement: Where Teams See the Most Value

Artificial intelligence, particularly Microsoft Copilot in Dynamics 365 Customer Engagement, is quickly becoming part of everyday work across ...

1 month ago

Microsoft Power Platform 2026 Release Wave 1: What Copilot and Agents Mean for Dynamics 365 Customer Engagement

In conversations with organizations over the past several months, a consistent question has started to surface: how do we actually use these A...

1 month ago

Azure Data Factory Tips for Reliable Microsoft Dynamics 365 CE and Dataverse Integrations

Reliable integrations between Microsoft Dynamics 365 Customer Engagement and external systems can become challenging. This is especially true ...

1 month ago

Dynamics 365 CE: Known Issues Creating Word Templates

A classic feature worth revisiting, today’s focus is Word Templates in Dynamics 365 CE/CRM. This tool remains a powerful option available for ...

2 months ago

Architecting Scalable Business Logic in Dynamics CRM Using Plugin Life Cycle

Dynamics CRM Plugin Life Cycle: Optimizing for Scalability means designing plugins in a way that keeps the system fast, stable, and easy to ma...

5 months ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy