While working in Dynamics 365 Finance & Operations, there are many situations where we need to read data from multiple legal entities instead of just the current company.
By default, any query or select statement in X++ only fetches records from the company you are logged into. But what if you want data from all companies?
That’s where CrossCompany comes into the picture.
What Is CrossCompany in D365 F&O?
CrossCompany allows you to read records from multiple legal entities in a single query without changing the company context.
Normally, D365 F&O automatically applies a DataAreaId filter behind the scenes. When CrossCompany is enabled, this filter is ignored and data is returned from all companies that the user has access to.
Example: Using CrossCompany in a Query
Below is a simple example where we want to read InventLocation records from all companies.
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
queryBuildDataSource = query.addDataSource(tableNum(InventLocation));
query.allowCrossCompany(true);
No comments:
Post a Comment