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 :
Small and medium business | Business Central, N...
Answered

Reports and stopping execution of code with errors like testfield, error, etc.

(0) ShareShare
ReportReport
Posted on by

Hi community,

I was working on debugging something in report 99001017 "Calculate Plan - Plan. Wksh." when I encountered something interesting.

Somewhere down the line, inside a codeunit, a Validate("No.") is called on the Requisition Line. This has the ability to throw an error.

I was wondering, why does this not stop the execution of code?
When i throw an error inside a codeunit, all code stops.


Is it because this is inside a 'OnAfterRecord' of a report?

I couldn't find any explanation as to why the code continues with the next record.

I have the same question (0)
  • Suggested answer
    Andy Sather Profile Picture
    Microsoft Employee on at

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

  • Verified answer
    Tabrez Ajaz Profile Picture
    787 on at

    Hello @san,

    As the codeunit, is call for every time for each Requisition Line, and on "Calculate Plan - Plan. Wksh" also handles the error when it occurs, after execution you can see the errors that occurred for any requisition line. So in this case, if any error occurs for 1 requisition line will not affect other lines in the planning process, and after execution, you can see a warning or error. Make sure to resolve the error before going to do further action in the process.

    You can also test this by doing something below:

    * Create a codeunit test

    * Add any method in this codeunit

    * Call this method in OnRun of the codeunit

    -> Now where you are calling this codeunit do something like:

    var

     errorText: Text;

     yourCodeunit: Codeunit "Your Codeunit";

    begin

     ClearLastError();

     if not yourCodeunit.Run then begin

       errorText:=GetLastErrorText();

     end;

    end;

    Now you have the error text in the errorText variable you save the error in any table or just display it by using the ERROR or Message.

    Good Luck :)

  • Community Member Profile Picture
    on at

    Thanks for the answer and the example! It makes more sense now.

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,993 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,116 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 557 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans