Skip to main content

Notifications

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;        }
 
  • Harshal Jain Profile Picture
    Harshal Jain 162 on at
    How to apply cross company in joins in ax ?
    Hi Martin, got my mistake. Thanks for the solution.
  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    How to apply cross company in joins in ax ?
    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.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    How to apply cross company in joins in ax ?
    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans