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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to insert data in custom table in respective company using data entity

(1) ShareShare
ReportReport
Posted on by 97
Hi All,

I have extension of EcoResReleasedProductV2Entity.
I have written this code in postLoad eventhandler to insert records in custom table.

But now the issue is its inserted all the companies records of entity into the current running company in the custom table.
Ex:  if i run the data management in USMF company , in entity if i am having inventTable related records in 5 company then it's inserting all the 5company information in USMF entity of my custom table. So in entity i am having records from different legal entity but in my custom table all records inserted in one legal entity.

I used crossCompany, changeCompany keywords but its not working

How to insert data in respective legal entity as of data entity data.
 
 /// <summary>
    ///
    /// </summary>
    /// <param name=/_sender/></param>
    /// <param name=/_eventArgs/></param>
    [DataEventHandler(tableStr(EcoResReleasedProductV2Entity), DataEventType::PostedLoad)]
    public static void EcoResReleasedProductV2Entity_onPostedLoad(Common _sender, DataEventArgs _eventArgs)
    {
        EcoResReleasedProductV2Entity EcoResReleasedProductV2Entity = _sender;
        EcoResReleasedProductV2Entity EcoResReleasedProductV2EntityLoc;
        ITPriceHistory  priceHistory;
        //select crosscompany EcoResReleasedProductV2EntityLoc
        //    where EcoResReleasedProductV2EntityLoc.RecId == EcoResReleasedProductV2Entity.RecId;
        changecompany(EcoResReleasedProductV2EntityLoc.DataAreaId)
        {
        ttsbegin;
        priceHistory.Price = EcoResReleasedProductV2Entity.PurchasePrice;
        priceHistory.ContractPrice = EcoResReleasedProductV2Entity.ContractPrice;
        priceHistory.ItemId = EcoResReleasedProductV2Entity.ItemNumber;
          //  priceHistory.DataAreaId = EcoResReleasedProductV2Entity.DataAreaId;
        priceHistory.insert();
        ttscommit;
        }
    }
    
Thanks in adnvance.
I have the same question (0)
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi PJ_John,
     
    Isn't it because you are using EcoResReleasedProductV2EntityLoc in the change company instead of the other variable "EvoResReleasedProductV2Entity" that you filled from sender?
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Martin Dráb Profile Picture
    237,789 Most Valuable Professional on at
    Writing to another table every time when a record is loaded from database? What purpose does it serve? It sounds like a performance killer creating a plenty of duplicate records (or causing errors), because the same product surely can be exported (or used in code) more than once.
     
    It sounds like a bad idea to me.
  • PJ JohnPaul Profile Picture
    97 on at
    Hi @martin,

    Thanks for your reply, can you please suggest me what will be the better place i can write code to insert some data of standard entity to my custom table.

     
  • Martin Dráb Profile Picture
    237,789 Most Valuable Professional on at
    Well, what code you should write and where you should place it depends on what logic you're trying to implement.
     
    Please start by describing the business requirement.
  • PJ JohnPaul Profile Picture
    97 on at
    Hi @Martin,

    I have created one custom table ( ITPriceHistory) , whenever the data imported through data management for release product entity , in standard entity we are having a field PurchPrice, that field value i need to insert in my custom table.

    So after each import operation i need to insert the imported PurchPrice value in new custom table. So where can i perform this insert operation?
     
    Thanks
  • Verified answer
    Martin Dráb Profile Picture
    237,789 Most Valuable Professional on at
    Is it limited to data import? Can you confirm that no change should be logged in ITPriceHistory if price changes inside F&O, such as by a user or in code? It would sound strange.
     
    Even if you say that it can't be changed by users and you don't have any code changing the value, it would make sense to do it on table level rather than on a particular way of changing the data. Also, even if there is no code changing the data, someone may add such code tomorrow, therefore depending on it isn't the best approach.
     
    If you insist on doing it in the entity, postLoad() is a bad choice, because that's a method called when reading the data, not when writing it. You should use something like persistEntity().

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans