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? 

  • Suggested answer
    Greg Enns Profile Picture
    1,102 on at
    RE: ASSERTERROR in BC

    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.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: ASSERTERROR in BC

    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!

  • NancyPaul Profile Picture
    40 on at
    RE: ASSERTERROR in BC

    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
    RE: ASSERTERROR in BC

    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".

  • Suggested answer
    Greg Enns Profile Picture
    1,102 on at
    RE: ASSERTERROR in BC

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

  • NancyPaul Profile Picture
    40 on at
    RE: ASSERTERROR in BC

    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
    Suresh Kulla Profile Picture
    47,789 on at
    RE: ASSERTERROR in BC

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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 628 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 495

#3
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 395

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans