Tuesday 21 February 2017

How to add methods to table using extension in D365 FO

D365F&O won’t allow user to add new methods to table directly. So here I will be demonstrating how to add new methods to table using extension class.

Lets say our requirement is to add new method to VendTable to get address of Vendors.

First step is to create a class, have a name that has the _Extension suffix and should be static.

public static class VendTable_Extension
{
}

Next Step is to create method, method should always be public static and first parameter should be Table buffer.

public static class VendTable_Extension
{
    public static Notes getVendAddress(VendTable vendTable)
    {
        DirPartyTable       dirPartyTable;
        LogisticsLocation   logisticsLocation;

        select dirPartyTable where dirPartyTable.RecId == vendTable.Party
        join logisticsLocation
        where dirPartyTable.PrimaryAddressLocation == logisticsLocation.RecId;      
       
        return logisticsLocation.postalAddress();
    }

}

Once we will build our project, this method will be usable as if it is method of VendTable.

I have tested the same using job.

class VendTable_Demo
{        
    /// <summary>
    /// job to test vendtable extension method
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {    
        VendTable vendTable;

        vendTable = VendTable::find("1001"); 
        
        info(strFmt("Vendor Address - %1",vendTable.getVendAddress()));
      
    }



Output:-


THANK YOU
















5 comments:

  1. That's reall an amazing post. Thanks for letting us know about it. This is interesting site piknu about instagram

    ReplyDelete
  2. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.
    Best CRM System

    ReplyDelete
  3. Hey Can you help in fetching just the country code from primary address

    ReplyDelete