Tuesday, June 6, 2017

Tips : How to override super call by event Handler

Hi everyone,

Today, just a tips, maybe usefull for someone (I hope).

With Dynamics 365 for operations, developer used to implement Event Handler method, based on standard code.
Sometimes, it would be interesting to override the super of the event handler caller, if we want to cancel for example the process in an iteration.

That's possible by a simple way, too little documented in my opinion.

Here a sample of code :

Source


    /// 
    ///Override the create method logic
    /// 
    /// 
    /// 
    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Creating)]
    public static void SalesTable_OnCreating(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormDataSourceCancelEventArgs ce = e as FormDataSourceCancelEventArgs;

        ce.cancel(true); // remove the super call

    }