Wednesday, February 1, 2017

AX 7 Using Extensions

In AX 7  X++ supports extension methods similarly to C#, it really helps develop better without modify base objects.

We can create table/class methods without touching respective object.


Step 1 : Create a final class with Prefix of _extension

Step 2 : Add attribute mentioning Extensionof  for tablestr and mention table name

Step 3 : Add Public method to handle business logic

Step 4 : Call the method in required place



Sample Class to Handle DirPersonName table fullname method

[ExtensionOf(tableStr(DirPersonName))]
final class MyDirPersonName_Extension
{
    public PersonName fullName()
    {
        return strFmt('%1 %2 %3'this.FirstName, this.MiddleName, this.LastName);
    }
}

You can call above method in your program

while select dirPersonName
{
    info(dirPersonName.fullName());
}
source : https://blogs.msdn.microsoft.com/mfp/2015/12/15/x-in-ax7-extension-methods/

No comments:

Post a Comment