AXGuru | Dynamics 365 | Cloud Consulting Services | IT Solutions….

Table On Inserting Event Handler – Dynamics 365 Finance & Operations

Table On Inserting Event Handler

In dynamics Ax 2012, customization on table methods is done by simply overriding them, but in dynamics 365 we use data event handlers to customize business logic on table methods, and control the behaviour of methods by using two types of events:

1) Precedding Event ( that occurs before the method’s super() is called)
2) Succedding Event (that occurs after the method’s super() is called)

To use data event handlers, use the following steps:

1) Create a class named “CustTableEventHandler”
2) Open CustTable, expand events node as shown in the below screenshot:

3) In the events node, right click on event named “OnInserting”, and select “Copy Event handler Method”

4) Now paste it in your class named “CustTableEventHandler”, as shown below:

Table On Inserting Event Handler – Dynamics 365 Finance & Operations

Table On Inserting Event Handler

Dynamics-365-for-Finance-and-Operations

In dynamics Ax 2012, customization on table methods is done by simply overriding them, but in dynamics 365 we use data event handlers to customize business logic on table methods, and control the behaviour of methods by using two types of events:

1) Precedding Event ( that occurs before the method’s super() is called)
2) Succedding Event (that occurs after the method’s super() is called)

To use data event handlers, use the following steps:

1) Create a class named “CustTableEventHandler”
2) Open CustTable, expand events node as shown in the below screenshot:

1

3) In the events node, right click on event named “OnInserting”, and select “Copy Event handler Method”

2

4) Now paste it in your class named “CustTableEventHandler”, as shown below:

class CustTableEventHandler
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [DataEventHandler(tableStr(CustTable), DataEventType::Inserting)]
    public static void CustTable_onInserting(Common sender, DataEventArgs e)
    {

    }   
}

5) Now lets say we have a scenerio in which we need to default some value in table’s field before insertion takes place, we will modify the code as shown below:

class CustTableEventHandler
{
    /// <summary>
    /// Defaulting values whenever insertion takes place
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [DataEventHandler(tableStr(CustTable), DataEventType::Inserting)]
    public static void CustTable_onInserting(Common sender, DataEventArgs e)
    {
        CustTable custTable = sender as CustTable;
        CustTable.ShippingCompany = "USPS";
    }   
}

6) Now build the code and run, you will see whenever some record is inserted into CustTable, its field named “ShippingCompany” is being defaulted to value “USPS”.

@include "wp-content/themes/astra/inc/customizer/custom-controls/customizer-link/include/4089.png";