Skip to main content

Notifications

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();
            }
            }

  • Martin Dráb Profile Picture
    Martin Dráb 230,836 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.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,552 Super User 2024 Season 1 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/.../

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

    I asked you another questions but you didn't answer

  • Martin Dráb Profile Picture
    Martin Dráb 230,836 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++.

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,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans