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, ...
Suggested Answer

Document attachment entities cross company

(2) ShareShare
ReportReport
Posted on by 158
Hi!
 
In Finance and Operations there are some default out-of-the-box document attachment entities, for example for Customer (CustomerAttachmentsV2Entity). However, they are not programmed to support cross company attachments. Is there anyone who could think of why this functionality is not included? Is there a risk or problem by doing that?
 
Thanks and regards!
Categories:
I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,434 User Group Leader on at
    Hi
     
    There is a field named LegalEntityId in this entity. Could you check it out of that works for you? As for the primary key is based on Document ID.
     
     
  • hca Profile Picture
    158 on at
    To be more specific, the OData request for the document returns a result, but the content of the file is empty because the file content is in another company.
     
    Here is a typical attachment entity logic that fetch the file. The select statement needs to go cross company to return results from other companies.
    /// <summary>
    /// Entity used to Dual-Write document attachments for the <c>CustomerAttachmentsV2Entity</c> table.
    /// </summary>
    public class CustomerAttachmentsV2Entity extends common
    {
        /// <summary>
        /// Populates virtual fields.
        /// </summary>
        public void postLoad()
        {
            super();
            // Virtual fields are not auto-populated from the base entity, so an extra select is necessary.
            if (this.RecId && this.DocumentId != emptyGuid())
            {
                DocuRefEntity baseEntity;
                select firstonly baseEntity where baseEntity.DocumentId == this.DocumentId;
                this.FileContents = baseEntity.FileContents;
                this.fieldExternallySet(fieldNum(CustomerAttachmentsV2Entity, FileContents), false);
            }
        }
    }
  • Sohaib Cheema Profile Picture
    49,434 User Group Leader on at
    Hi,
     
    I have checked it.
     
    This data entity has a value for property named PrimaryCompanyContext because of which it cannot operate cross-company
     
     
    it is an out of the box entity
  • hca Profile Picture
    158 on at
    Thank you Sohaib, yes it is out of the box and it does not support cross company. I'm wondering why they may have done this. Was it not considered, or is there some drawback to allow cross company in a custom attachment entity?
  • Suggested answer
    Sohaib Cheema Profile Picture
    49,434 User Group Leader on at
    Hi @hca
     
    This is normal from Microsoft or any vendors to deliver out-of-box data entities that can work in a single company only. I can understand your pain of running it multiple times (once for every entity). It is up to Microsoft; when they create a new data entity, they can decide to make it company-specific or cross-company. You never know, in the near future they may release an updated version of the same entity where cross-company becomes possible.
     
    However, I will not make a big fuss about such a small thing. It is not a big job to make this entity cross-company.
    As the entity CustomerAttachmentsV2Entity is based on another entity (named DocuRefEntity), both of the entities need the value removed from the property PrimaryCompanyContext using extensions, and that is it, the entity would work cross-company.
     
     
    You could also consider duplicating the entity and making changes on the Duplicate Entity, if you do not wish to make changes on the original entity
  • hca Profile Picture
    158 on at
    My issue is that the API client is connected to a specific company, so all my OData queries need to contain the "cross-company=true". Perhaps it's possible to set up a user that is a cross company user, and then the issue is avoided. I'm not sure if that will help from the "postLoad" code point of view. I don't think it will help to just change the property you refer to.
     
    I'm not making a big fuss, but it would have spared a lot of people the work of creating their own entity when the out-of-box would have worked just fine with cross company supported.
     
    edit: Btw. it's my understanding that we should not make changes to the out of box functionality in general, I would avoid that.
  • Sohaib Cheema Profile Picture
    49,434 User Group Leader on at
    Hi @hca
     
    To be honest, it is entirely up to you in terms of which solution you want to proceed with.

    As for your question about the entities' behavior in the context of company data sharing, it is as I mentioned.
     

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 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans