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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Try catch doesn't work in while loop x++

(0) ShareShare
ReportReport
Posted on by 163

I made a report that validate every line in General Journal this my code , I tried to remove ttsbegin and ttscommit , put them in try or in catch but doesn't work 

It doesn't hit the catch statement 

   while select  LedgerJournalTrans
            order by LedgerJournalTrans.LineNum
            where LedgerJournalTrans.JournalNum == JournalId
          //outer	join ledgerJournalTable
          //  where ledgerJournalTable.JournalNum == LedgerJournalTrans.JournalNum
          outer  join LedgerJournalProject
            where LedgerJournalProject.RefRecId == LedgerJournalTrans.RecId
        {
 
            LedgerJournalTmp.clear();
            LedgerJournalTmp.JounralNum = LedgerJournalTrans.JournalNum;
            LedgerJournalTmp.LineNumber = LedgerJournalTrans.LineNum;
            
            
            try 
            {
                    LedgerJournalPost::simulatePost(JournalTrans,JournalTransId,true, true, false, formStr(LedgerJournalTransDaily), ledgerJournalEngine);
            }
            
            catch 
            {
             sysInfologEnumerator = SysInfologEnumerator::newData(infolog.infologData());
                infolog.cut();
                while (sysInfologEnumerator.moveNext() )
                {
                    message = sysInfologEnumerator.currentMessage();
                    str dim = 'You must select a value in the Department field in combination with the following dimensions values that are valid:';

                    if (strScan(message,dim,1,strLen(dim)) || strScan(message,'Dimension values were validated with this account structure: Contrack FM - With Dimensions',1,1000))
                        LedgerJournalTmp.DefaultDimension = NoYes::Yes ;

                    if( message == 'Project stage Finished does not allow recording in this project.')
                    LedgerJournalTmp.ProjectStatus = NoYes::Yes;
                    
                    if (strScan(message,strFmt( 'MainAccount %1 is closed.',mainAccount),1,strLen(strFmt( 'MainAccount %1 is closed.',mainAccount))) || strScan(message,strFmt( 'MainAccount %1 is closed.',mainAccount),1,strLen(strFmt( 'MainAccount %1 is closed.',mainAccount))))
                        LedgerJournalTmp.LedgerSuspend = NoYes::Yes ;
                    //else if(( message == 'Dimension values were validated with this account structure: Contrack FM - With Dimensions')||(message == strFmt("Account structure SystemGeneratedHierarchyProject for the combination %1 is not valid for ledger CFM" ,projId)))
                    //LedgerJournalTmp.DefaultDimension = NoYes::Yes;

                    if( message == strFmt("Period for %1 does not exist." ,LedgerJournalTrans.TransDate)  || strFmt("Fiscal period for %1 is not open." ,LedgerJournalTrans.TransDate))
                    LedgerJournalTmp.TransDate = NoYes::Yes;

                    if(strScan(message,"The combination project/category is mandatory, but does not exist for project",1,1000) != 0)
                    LedgerJournalTmp.CategoryCombination = NoYes::Yes;
                    }
            LedgerJournalTmp.insert();
            }
            }

I have the same question (0)
  • Martin Dráb Profile Picture
    237,681 Most Valuable Professional on at
    RE: Try catch doesn't work in while loop x++

    This is a duplicate. It's already discussed in Try catch doesn't work in RDP class ProcessReport () method x++.

  • Menna Allah Ahmed Profile Picture
    163 on at
    RE: Try catch doesn't work in while loop x++

    I asked you another questions but you didn't answer

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: Try catch doesn't work in while loop x++

    Hi Menna, I think even if you manage to get Catch statement hit, your code will not work. You are trying to insert error logs in a temporary table. Instead you should create a regular Log table. (Not sure why your catch statement is not hit).

    check this article

    dynamicsaxinsight.com/.../

  • Martin Dráb Profile Picture
    237,681 Most Valuable Professional on at
    RE: Try catch doesn't work in while loop x++

    I'm not going to duplicate the discussion; find my reply in the original thread.

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans