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

Announcements

No record found.

News and Announcements icon
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
    239,022 Most Valuable Professional on at

    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

    I asked you another questions but you didn't answer

  • Suggested answer
    Mohit Rampal Profile Picture
    12,573 Moderator on at

    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
    239,022 Most Valuable Professional on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 613

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 455 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 292 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans