This post is machine-translated. The original post in german language can be found here.

Extend insert-method using chain of command in an augmentation class

In this post I want to show how chain of command can replace pre- or post-events.

After having created / opened the desired project, you can create a new object of type Class via the context menu of the project under Add > New item. Now you should rename your class, important here is the extension _Extension.

Screenshot

After that, a simple class is available that presents itself as follows

class FMCustomer_DMO_Table_Extension
{
}

Now we change the class via the ExtensionOf attribute and add the final modifier. Classes identified in this way are also referred to as augmentation classes.

[ExtensionOf(tableStr(FMCustomer))]
final class FMCustomer_DMO_Table_Extension
{
}

Now we switch back to the Application Explorer, look for the table we want to expand there and expand the Methods node. Now for the respective method, in the example the insert(), and select the option View Code via the context menu.
This opens the method in the workspace from which we copy the definition of the method to the clipboard.

public void insert()
{
}

We insert this code in the extension class.

Then we insert the call of the original method into our code

[ExtensionOf(tableStr(FMCustomer))]
final class FMCustomer_DMO_Table_Extension
{
    public void insert()
    {
       next insert();
    }
}

Then you can insert the appropriate code before calling next() or after this call. Depending on the position of this code, we have realized a pre- or post-event handler.

Im konkreten Beispiel wird vor dem Aufruf der Original insert()-Methode ein Feld ggf. mit einem Standardwert befüllt.

[ExtensionOf(tableStr(FMCustomer))]
final class FMCustomer_DMO_Table_Extension
{
    public void insert()
    {
        if ( !this.Email)
        {
            this.Email = "someone@somewhere.com";
        }

        next insert();
    }
}

This article was created based on version 7.3 with Platform-Update 12 and installed Fleet Management Sample Application.

These post applies to following version:
Dynamics 365 for Finance and Operations

Add comment
 
 

 

 
 
 
Posts of the actual month
Dezember 2024
MoTuWeThFrSaSu
 1
2345678
9101112131415
16171819202122
23242526272829
3031 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.