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

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
    237,878 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,827 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

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans