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

Get data of all companies from CompanyInfo table

(1) ShareShare
ReportReport
Posted on by 8
Hello everybody, 
 
I need to select data from all companies in CompanyInfo table through x++, ax 2012.
So what I basically need to do is a select crosscompany for CompanyInfoTable, based on a specific field. 
 
For example, I have added FieldA(NoYesID - EDT) on CompanyInfo table. 
 
I have written this query, but it doesn't show the data if the FieldA is checked for another company different from the current company. 
 
CompanyInfo companyInfo;
;
 
select firstonly crossCompany companyInfo
where companyInfo.FieldA == NoYes::Yes.
 
Is there any way to write this query or a similiar one in x++?
 
Thanks in advance.
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    Please tell us more about your problem. It's not clear to me what you mean by "it doesn't show the data if the FieldA is checked for another company different from the current company".
     
    Note that your requirement was to get all companies matching some criteria, but your code returns a single company (because you've used the firstOnly keyword).
  • Suggested answer
    Mohit Khandelwal Profile Picture
    2 on at
    Though your requirement isn't entirely clear, based on your query, I believe you need to enclose the "while select" statement within a changeCompany loop like this:
    while select dataArea where !DataArea.isVirtual
    {
        changeCompany(dataArea.dataAreaId)
        {
            while select * from companyInfo
            {
                ...
            }
        }
    }
    

     
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    Using a single cross-company query is more efficient than running a separate query for every company. You don't need changeCompany just to fetch records; you have crossCompany for this purpose.
  • Verified answer
    Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at
    Hello,
     
    Like Martin mentioned, I think your issue is the "firstOnly" keyword which selects the first record only. In addition, you don't have to use the crossCompany keyword in this case because the data is shared between all companies/legal entities anyway.

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans