Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Issue with cross companies data with generaljournal entry table

Posted on by 1,869
Hello,
 
The below code always excuting the data from default company dat. How can I get the data from USMF and other companies. Please advice
 
 class TestJournalCode
{
    public static void main(Args _args)
    {
        GeneralJournalAccountEntry genralJournalAccountEntry, genralJournalAccountEntryprev;
        GeneralJournalEntry  generalJounralEntry;
        MainAccount mainAccount;
        Date fromDate, toDate;
        fromdate =str2Date(/1/21/2015/,213);
        toDate = str2Date(/1/21/2015/,213);
      //  DataAreaId dataAreaId;
       // List journallist = new List(Types::Class);
        ;
       select crosscompany generalJounralEntry order by dataAreaId 
                    where generalJounralEntry.DataAreaId == /USMF/
                    &&  generalJounralEntry.AccountingDate >= fromdate
            && generalJounralEntry.AccountingDate <= toDate;
      
          Info(generalJounralEntry.DataAreaId);
          Info(generalJounralEntry.JournalNumber);
         
        
    }
}
 
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    Issue with cross companies data with generaljournal entry table
    Did you find any record in USMF company? No. Therefore your expectation that you loaded a record with USMF value in DataAreaId field is wrong.
     
    Did you find any record at all? No. Your code pretends that a record was fetched and it's showing information about the record, but it's actually a lie caused by a bug. No record was found therefore there is nothing meaningful to show. You're confused because the bug in your code produces a meaningless output.
  • Faqruddin Profile Picture
    Faqruddin 1,869 on at
    Issue with cross companies data with generaljournal entry table
    Thank you for your response. I checked there is no records founds. I use below scenario as well still there is no data found. And its strange in below query the dataareaid is USMF and in the output dat.
     
     
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    Issue with cross companies data with generaljournal entry table
    All right, so that's the answer. Your code doesn't return any data from USMF company because no such a record exists. You forgot to check whether a record was found.
  • Faqruddin Profile Picture
    Faqruddin 1,869 on at
    Issue with cross companies data with generaljournal entry table
    Please find output below.
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    Issue with cross companies data with generaljournal entry table
    Does the query finds any record at all? That it doesn't is the only explanation I have so far.
     
    Let me throw away all the unnecessary code and add the check:
    GeneralJournalEntry generalJournalEntry;
    
    select firstOnly crossCompany generalJournalEntry
        where generalJournalEntry.DataAreaId == 'USMF'
           && generalJournalEntry.AccountingDate == mkDate(21, 1, 2015)
    
    if (generalJournalEntry)
    {
        info(generalJournalEntry.DataAreaId);
        info(generalJournalEntry.JournalNumber);
    }
    else
    {
        warning("No record found");
    }
    Please run it and let us know what it returned.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans