web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to apply cross company in joins in ax ?

(0) ShareShare
ReportReport
Posted on by 162
Hi,
I am trying to get the data across all the legal entities but it's working only for the current legal entities. For other legal entity it doesn't give result.
 
GeneralJournalAccountEntry generalJournalAccountEntry;        LedgerEntry ledgerEntry;        LedgerEntryJournal ledgerEntryJournal;        GeneralJournalEntry generalJournalEntry;        if (_generalJournalAccountEntryRecId != 0)        {            select firstonly crosscompany generalJournalAccountEntry                where generalJournalAccountEntry.RecId == _generalJournalAccountEntryRecId            join  generalJournalEntry                where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry &&                      generalJournalEntry.Ledger == Ledger::current()            outer join  ledgerEntry                where ledgerEntry.GeneralJournalAccountEntry == generalJournalAccountEntry.RecId            outer join  ledgerEntryJournal                where ledgerEntryJournal.RecId == generalJournalEntry.LedgerEntryJournal;        }
 
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    238,738 Most Valuable Professional on at
    Let me format your code a bit:
    GeneralJournalAccountEntry generalJournalAccountEntry;
    GeneralJournalEntry generalJournalEntry;
    LedgerEntry ledgerEntry;
    LedgerEntryJournal ledgerEntryJournal;
    
    
    if (_generalJournalAccountEntryRecId != 0)
    {
        select firstonly crosscompany generalJournalAccountEntry
            where generalJournalAccountEntry.RecId == _generalJournalAccountEntryRecId
                join generalJournalEntry
                    where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
                       && generalJournalEntry.Ledger == Ledger::current()
                outer join ledgerEntryJournal
                    where ledgerEntryJournal.RecId == generalJournalEntry.LedgerEntryJournal
            outer join ledgerEntry
                where ledgerEntry.GeneralJournalAccountEntry == generalJournalAccountEntry.RecId;
                
    }
    I see you're filtering the data by Ledger::current(), which is the ledger of the current company (CompanyInfo::find()). I think this is the cause of your problem.
  • GirishS Profile Picture
    27,833 Moderator on at
    Hi Harshal,
     
    I think there is no need of cross company keyword here as all the table you are using is global.
    So as Martin mentioned, it may be due to the Ledger:;Current().
     
    Thanks,
    Girish S.
  • Harshal Jain Profile Picture
    162 on at
    Hi Martin, got my mistake. Thanks for the solution.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 577 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 309

#3
Diego Mancassola Profile Picture

Diego Mancassola 259

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans