Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Cross company freezes

Posted on by 1,272

Hi, I am facing a strange issue when running the below cross company query

  while select crossCompany specTrans
            where specTrans.SpecCompany == _ledgerJournalTrans.company() &&
                specTrans.SpecTableId == _ledgerJournalTrans.TableId &&
                specTrans.SpecRecId == _ledgerJournalTrans.RecId
            join custTransOpen
                where specTrans.RefCompany == custTransOpen.DataAreaId &&
                    specTrans.RefTableId == custTransOpen.TableId &&
                    specTrans.RefRecId == custTransOpen.RecId
            join custTrans
                where custTransOpen.RefRecId == custTrans.RecId
            join custTransCustomer
                where custTrans.AccountNum == custTransCustomer.AccountNum


AX freezes when I run this. But when I run it without the crossCompany keyword it runs smoothly. I have verified that this query only returns one record.

the actual code can be found in \Classes\LedgerJournalTransUpdateCust\checkSettleVoucher

Any idea why this would happen.

*This post is locked for comments

  • Verified answer
    dynamics developer Profile Picture
    dynamics developer 1,272 on at
    RE: Cross company freezes
    I am not sure if this was the real problem but we had same customers and vendors in muliple companies and the it was causing the freeze.

    So I added the last line below as a fix for both customer and vendor

    while select crossCompany specTrans
       where specTrans.SpecCompany == _ledgerJournalTrans.company() &&
             specTrans.SpecTableId == _ledgerJournalTrans.TableId &&
             specTrans.SpecRecId == _ledgerJournalTrans.RecId
          join custTransOpen
             where specTrans.RefCompany == custTransOpen.DataAreaId &&
                   specTrans.RefTableId == custTransOpen.TableId &&
                   specTrans.RefRecId == custTransOpen.RecId
          join custTrans
             where custTransOpen.RefRecId == custTrans.RecId
          join custTransCustomer
             where custTrans.AccountNum == custTransCustomer.AccountNum
      &&  custTransCustomer.dataAreaId == _ledgerJournalTrans.company() //added 
  • Suggested answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Cross company freezes

    Do you have DataAreaId literals enabled to avoid parameter sniffing for your SQL queries? In case you are using multiple company accounts with varying data sizes, it is a good practice to have it on. Unfortunately crosscompany selects involve multiple companies, for which the query processor engine will have a harder time to optimize this.

    As Sukrut said, you need to have SQL Server maintenance plans in place for fragmented indexes and you should regularly update statistics too.

    A "freeze" typically means that your SQL Server is busy, have you tried to capture the Query execution plan and see what is wrong with that? Having a field list list as mentioned above is beneficial for the actually used information. But the biggest boost always comes if you have no fragmentation, statistics are updated, and you have covering indexes created for the frequently used queries such as the settlements you have problems with.

    Please provide additional details of your findings for the mentioned areas.

  • dynamics developer Profile Picture
    dynamics developer 1,272 on at
    RE: Cross company freezes

    I think 2012 code should be better. But as I expected this change didn't help. It's something wrong with the environment because on DEV it's fine. On TEST it freezes. I already checked the data and all the joins are fine and returns 1 row from each table. I will try and run it on SQL now

  • dynamics developer Profile Picture
    dynamics developer 1,272 on at
    RE: Cross company freezes

    Thanks. let me try adding these.

    What version are you using?

    Mine is

    0451.1.jpg

  • dynamics developer Profile Picture
    dynamics developer 1,272 on at
    RE: Cross company freezes

    Sure but it is standard AX code. I am not sure why they used crossCompany here

    Anyway my question is not about the code but how the crossCompany is causing AX to freeze?

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans