Raju's Dynamics AX / Dynamics 365 Finance and Operations Blog

BLOG BY RAJU. DYNAMICS AX , DYNAMICS 365 FINANCE AND OPERATIONS EXPLORER

Example of using onInserting Event handler D365FO.

I just wrote a basic example of how to change a value while inserting the record in VendTable.

Here I am trying to Update VendGroup if the credit limit is greater than 100. For example, when i create a new vendor and added the details in Vendor Group as “10”(10 is one of the source values in VendGroup master data). and i add the credit limit as 3000. Then record should be saved with VendGroup as “20” instead of 10. Below code will do that.

For this i need to do below steps.

Create a new Class and name it as VendTable_EventHandler.

Then Open VendTable table and Right Click on Events > and Click Copy Event Handler.

Then paste it in the Class. Code is like below.

class VendTable_EventHandler
{

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(VendTable), DataEventType::Inserting)]
public static void VendTable_onInserting(Common sender, DataEventArgs e)
{
    VendTable VendTable = sender as VendTable;

    if(VendTable.CreditMax > 100)
    {
        VendTable.VendGroup = "20";

    }


}

}

Published by

Leave a comment

Design a site like this with WordPress.com
Get started