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...
Suggested Answer

ASSERTERROR in BC

(0) ShareShare
ReportReport
Posted on by 40

HI,

In NAv I generally use  ASSERTERROR to rollback the transaction without error.

How can we do it in BC? Microsoft said we should not use this command in Production code.

Is there any ways I rollback all the transaction( no writetransaction in DB)  and continue with process without error and stooping the program? 

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    You can just use Error('') without any message it will rollback everything

  • NancyPaul Profile Picture
    40 on at

    Thank you so much for the reply.Suresh Kulla.

    Error() command will stop the program completely and cannot continue with it.

    Do you have any more idea?

  • Suggested answer
    Greg Enns Profile Picture
    1,106 on at

    I think what you are looking for is TRY functions or IF Codeunit.RUN THEN ...

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Nancy,

    ASSERTERROR is used mainly for the statement that contains the error, so system can continue the execution of code. Use of ASSERTERROR is recommend while doing the Automated Testing in Dynamics NAV / D365 BC.

    In case if you need to rollback the transaction you need to use ERROR('') at the end of the code. So the transaction will be rolled back. Microsoft also do the same thing in "Preview Posting".

  • NancyPaul Profile Picture
    40 on at

    Hi Naveen,

    I have a report that reads data from xml file and created items in NAV and at the end it updates statistical table with data like active item, inactive items, deleted item, updated items count. Now there is a requirement, the like preview posting run the report or schedule the report and at the end roll back all write transaction and update only statistical table only. Using Error statement will stop the program completely and   statistical data in table cannot be updated.

    As suggested by Greg Enns, I can use if codeunit.run but how to get statistical date?

    Any suggestions will be appreciable.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Nancy,

    As per your above comment, you need to roll back all the write transaction at the end of the report execution and only want to write data into Statistical table.

    If that is the case, then you can not use Error('') as it will roll back everything.

    This requirement seems to be complicated as you need to both roll back and write operation together.

    I don't think it is possible to perform roll back and write operation together. It should be either or.

    You can try with COMMIT and ERROR('') to perform roll back and write operation together but not sure how it will fulfill your requirement.

    All the best!

  • Suggested answer
    Greg Enns Profile Picture
    1,106 on at

    It sounds to me like you need to use temporary tables.

    A temporary table starts as an empty table. So you add the necessary records to the temporary table, do your analysis, make the updates to the database that you want to, and when you're done, the temporary table disappears from memory.

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,577

#2
YUN ZHU Profile Picture

YUN ZHU 888 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 778 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans