Friday, 8 February 2019

TABLE INIT VALUE IN D365 EVENT HANDLER DATASOURCE tABLE_Post/PRE_initValue

HOW TO CREATE INIT VALUE EVENT HANDLER IN D365 AT TABLE LEVEL


In Table Datasource Events > right click on Init Value > Copy Post/Pre Event Handlers
There are a few rules for augmentation classes:
  • They must be final.
  • They must be suffixed by _Extension.
  • They must be decorated with the [ExtensionOf()] attribute.
Create new Class and below code

Table Method Event Handler
EXAMPLE
class test SalesTableEventHanlders
//you can give any name ....or else you can decorate the class with extensionof(tablestr(salestable));
//in that case you would be able to get the fields directly using this keyword.
//shown at bottom
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(tableStr(SalesTable), tableMethodStr(SalesTable, initValue))]
    public static void SalesTable_Post_initValue(XppPrePostArgs args)
    {
        SalesTable SalesTable = args.getThis() as SalesTable;
        SalesTable.isclosed =NoYes::Yes;
    }
}


[ExtensionOf(tableStr(InventTable))] final class InventTable_Extension { public void myDefaultInventLocationId() { // This would have partner specific logic to initialize the new field. this.MyInventLocationId = this.inventLocationId(); } }


Thanks,
Vikas Mehta

No comments:

Post a Comment

AZURE INTERVIEW QUESTIONS AND ANSWERS

AZURE INTERVIEW QUESTIONS AND ANSWERES 2021 2. What is cloud computing? Explanation:  It is the use of servers on the internet to “store...