Tuesday, June 25, 2019

Add methods to tables through extension

Creating table extension does not allow you to add new methods.
As you can see in the screenshot below.
When i right clicked on Methods node of table extension there is no option available to add
" New Method ".




So to add a new method in standard table we need to follow the following steps.
  1. Create an Extension class for table
    Right click on your project then Add > New Item > Code > Class > Name "SalesConfirmHeaderMy_Extension" > AddThis class is called "augmentation class" of table "SalesConfirmHeader"



  2. There are a few rules for augmentation classes outlined by Microsoft
      1. They must be final.
      2. They must be suffixed by _Extension
      3. They must be decorated with the [ExtensionOf()] attribute.
  3. So first we need to fulfil these rules. Our augmented class will look like below (screenshot)




  4. Now you can add new methods to the augmentation class.These methods will then appear in intelliSense for variable of the "SalesConfirmHeadrTmp" table.
    In my case i added a "myTestMethod()" which sets the value in my custom field
    "MyStrField"of that table.



     Note : please visit this link to add a new field in standard table using extension approach
  5. Now create a run-able job just to verify that custom added method is displaying in the intellisense or not.
    Right click on your project then Add > New Item > Code > Runnable Class (Job) > Name "VerifyMethodJob" > Add

  6. Now create a variable "salesConfirmTable" for table "SalesConfirmHeaderTmp"
    and as you can see in the screenshot below that custom added method is displaying in the intellisense which was defined in the augmentation class



No comments:

Post a Comment

Post Event Handler

In Dynamics 365 F&O we are not allowed to add our custom logic in between the  core logic  but we can execute our custom logic before ...