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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

The IF codeunit.Run() then does not work

(3) ShareShare
ReportReport
Posted on by 17
Hi everybody, 
 
When I try the code of "codeunit.Run()"on the Cloud BC, I get the error. But this code can work on my previous project.
 
I also try with the code in the the reference document below, it also return the same error. 
 
The current test environment is Cloud BC, my previous project is On-Prem BC, Is that because this reason? 
 
Currently, my workflow is to loop to call a codeunit, then when this codeunit get an exception, I will go to next loop and do the same thing. If code of "if codeunit.Run() then...." can work for me, but now it return unknown exception.
I have try the [TryFunction], it can catch the exception message, but it cannot rollback the insert/modify transaction, so the [TryFunction] also not work for me.
 
Is there other ways to catch the exception message?
 

 
I have the same question (0)
  • Suggested answer
    RockwithNav Profile Picture
    8,637 Super User 2025 Season 2 on at
    Check if you are writing on the correct trigger(OnRun).
     
  • Verified answer
    CU19060955-1 Profile Picture
    17 on at
    Thank you. 
    After I double check, I find that there exist some other code conflict.
    In my other code, I call the CsvBuffer.DeleteAll() method of the record "CSV Buffer", this is conflict with the "if codeunit.Run()", I don't know what is the detail reason, but after I remove the DeleteAll() method, it can run fine.
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,150 Super User 2025 Season 2 on at

    Hope this might be helpful:

    The "An error occurred and the transaction is stopped" when if Codeunit.Run() then is used in Business Central Cloud (unlike older On-Premise) means unhandled errors inside the codeunit immediately stop the entire transaction, preventing the Run() method from returning FALSE.

    TryFunction is the correct way to handle and roll back transactions on error in modern BC. If your insert/modify isn't rolling back, it implies those operations are likely outside the TryFunction's scope or the error occurs elsewhere. You need to ensure the entire transactional unit of work is within the TryFunction to achieve rollback.

    ✅ Mark this answer as verified if it helps you.

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,092

#2
YUN ZHU Profile Picture

YUN ZHU 663 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 515

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans