web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to extend an out of the box data entity method?

(0) ShareShare
ReportReport
Posted on by 95

I have an out of the box entity that I've extended to include modified and created by fields. If a record existed before turning on the fields it's filled with a '?' and the customer doesn't want question marks in the output file, either the name or blank. In custom entities I had no problem adding code to the postLoad() method to change the '?'s to blank strings, but it's when I tried extending the out of the box entities.

An example here (shown below) https://community.dynamics.com/365/financeandoperations/b/365finopsknowledge/posts/how-to-extend-or-overwrite-dataentity-methods-in-d365-finance-and-operations-x is not working for me, the extended code is never hit when running the entity. I also tried using dataEntityViewStr isntead of tableStr for the extensionOf, neither are working.

Is this possible?

[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);
        }
               
    }

}

I have the same question (0)
  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at
    RE: How to extend an out of the box data entity method?

    Hi,

    You can use an event handler for "OnPostedLoad" event. I think That should serve your requirement.

  • Suggested answer
    Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    RE: How to extend an out of the box data entity method?

    Using CoC on postLoad() should work without problems.

    But the rest of the code is wrong and it won't even compile (if CustomDate is a date, as the name suggests). It's trying to add two dates together, which makes no sense. And it even converts one of them to a string, therefore it wants to add a string to a date, which makes even less sense. And the field is CreatedDateTime, not CreatedDateAndTime.

    The author meant something like this:

    [ExtensionOf(tableStr(SalesOrderHeaderV2Entity))]
    final class My_SalesOrderHeaderV2Entity_Extension
    {
        public void postLoad()
        {
            next postLoad();
    		
    		SalesTable salesTable = SalesTable::find(this.SalesOrderNumber);
    		this.CustomDate = DateTimeUtil::date(salesTable.CreatedDateTime);              
        }
    }

    By the way, please use Insert > Insert Code (in the rich-formatting view to paste source code, as I did.

  • nayshIB Profile Picture
    95 on at
    RE: How to extend an out of the box data entity method?

    Here's specifically what I'm using for the VendorInvoiceHeaderEntity and I have breakpoints in postLoad, it isn't being hit for some reason.

    [ExtensionOf(tableStr(VendorInvoiceHeaderEntity))]
    final class VendorInvoiceHeaderEntity_Extension
    {
         public void postLoad()
        {
            next postLoad();
    
            if (this.ModifiedBy1 == "?") this.ModifiedBy1 = "";
            if (this.CreatedBy1 == "?") this.CreatedBy1 = "";
        }
    }

  • Suggested answer
    Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    RE: How to extend an out of the box data entity method?

    It seems I misunderstood your problem. To achieve the same thing, simply write a data update job and modify values of ModifiedBy1 and CreatedBy1. Then you don't have to decrease performance by overriding postLoad().

    Using update_recordset is the best way to implement the data update job.

    If you was in a situation where it's not possible, you would be a better of writing a computed column than populating a virtual field in postLoad(). But in this case, neither seems to be needed.

  • WillWU Profile Picture
    22,361 on at
    RE: How to extend an out of the box data entity method?

    Hi nayshIB,

    If the value is based on a conditions, you can think of it as a calculated column or virtual field.This will not affect the field value of the original data entity.

    Please have a look at the document:docs.microsoft.com/.../data-entity-computed-columns-virtual-fields

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,167

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 867 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 617 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans