Skip to main content

Notifications

Announcements

No record found.

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

}

  • WillWU Profile Picture
    22,352 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

  • Suggested answer
    Martin Dráb Profile Picture
    231,758 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.

  • 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
    231,758 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.

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,758 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans