D365Ops: Using table event handler

Event handlers can be use to fire up your code without the necessary to customize and interfere on core logic and elements.

On the example below i’ll create an event handler that will initialize my new fields that I created using extension on the CustTable.

Find the method that you want to create the event handler, right-click and choose if you want to create a Pre or Post event handler.

1.JPG

Create a new classe and use the paste the eventHandler to create your method.

class RMSCustTableEventHandler
{
    [PostHandlerFor(tableStr(CustTable), tableMethodStr(CustTable, initValue))]
    public static void CustTable_Post_initValue(XppPrePostArgs args)
    {
        CustTable custTable = args.getThis() as CustTable;

        custTable.NewDateField = today();
    }

}

To use the validation with expected return value like validations, see the example below:

class RMSCustTableEventHandler
{
    [DataEventHandler(tableStr(CustTable), DataEventType::ValidatedWrite)]
    public static void CustTable_onValidatedWrite(Common sender, DataEventArgs e)
    {
        ValidateEventArgs   event       = e as ValidateEventArgs;
        CustTable           custTable   = sender as CustTable;

        boolean result = event.parmValidateResult();

        if (custTable.NewDateField >= today())
        {
            result = checkFailed("Your validation message");
        }

        event.parmValidateResult(result);
    }

}

If the table doesn’t have the method to create the event handler, use the pre-defined event available on the table under the node “Events”.

Capture

Advertisements
D365Ops: Using table event handler

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s