Tuesday, June 4, 2019

How to extend or overwrite dataentity methods in D365 Finance and Operations X++?

In this example I will be showing how to extend or overwrite dataentity methods.

In D365 7.1 and later versions Microsoft is not allowing to overwrite the standard objects. To overcome this, we need to use extensions.

We follow the same concept for extending tables, forms and classes methods.


Below example I'm overwriting/extending postload method in SalesOrderHeaderV2Entity entity.

Here I'm assigning sales order createddatetime value to some custom field.


[ExtensionOf(tableStr(SalesOrderHeaderV2Entity))]
final class SWClass_SalesOrderHeaderV2Entity_Extension
{
   

    public void postload()
    {
        next postload();
       
        SalesOrderHeaderV2Entity SalesOrderHeaderV2Entity = this;
       

        SalesTable                  salesTable = SalesTable::find(SalesOrderHeaderV2Entity.SalesOrderNumber);

       
        SalesOrderHeaderV2Entity.customdate += date2Str(salesTable.createddateandtime, 213,
                                                                DateMonth::Digits2,
                                                                DateSeparator::Slash,
                                                                DateDay::Digits2,
                                                                DateSeparator::Slash,
                DateYear::Digits4);
        }
               
    }

}


In the same way you can extend other methods as well.

@Rahul 

1 comment:

  1. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you.
    pożyczka w 5 minut bez zaświadczeń

    ReplyDelete

Power Automate vs Azure Logic Apps vs Azure Data Factory: What They Are, When to Use Them, and How to Integrate Non-Microsoft Systems

  In today’s cloud-first, API-driven enterprise landscape, automation and integration have become vital pillars of operational agility. Micr...