Skip to main content

Notifications

Announcements

No record found.

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.
  • Verified answer
    Anton Venter Profile Picture
    Anton Venter 19,457 Super User 2024 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
    Martin Dráb 230,371 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
    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
    Martin Dráb 230,371 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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans