web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    Anton Venter Profile Picture
    20,260 Super User 2025 Season 2 on at
    Get data of all companies from CompanyInfo table
    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.
  • Martin Dráb Profile Picture
    236,126 Most Valuable Professional on at
    Get data of all companies from CompanyInfo table
    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.
  • Suggested answer
    Mohit Khandelwal Profile Picture
    2 on at
    Get data of all companies from CompanyInfo table
    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
            {
                ...
            }
        }
    }
    

     
  • Verified answer
    Martin Dráb Profile Picture
    236,126 Most Valuable Professional on at
    Get data of all companies from CompanyInfo table
    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).

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,239

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 672 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans