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

How to prevent a page trigger from executing when clearing all records?

(0) ShareShare
ReportReport
Posted on by 2,304 Moderator

Hi everyone,

I have a page where I use the OnAfterGetCurrRecord trigger to perform some conditions based on the current record displayed on the page. However, I also have a functionality to clear all records on the page, as soon as I clear the records on the page.. it automatically closes the page.

pastedimage1676963770713v1.png

Is there a way to prevent the OnAfterGetCurrentRecord trigger from executing when I clear all records on the page? Can I add a condition to a trigger that runs before it to prevent it from executing?

Any help or suggestions would be greatly appreciated. Thank you!

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,786 Moderator on at

    Hi,

    I read your problem, but not sure what you have written in Clear button, is it possible to share the code?

    Thanks.

  • Govinda Kumar Profile Picture
    2,304 Moderator on at

    Hi Nitin Verma,

    Thank you for replying.. yes I can share the code if you want.. I'm just deleting all the records

    code on the action trigger
    pastedimage1676964195961v1.png

    code of clear import method
    pastedimage1676964254459v2.png

    Regards

  • Suggested answer
    Nitin Verma Profile Picture
    21,786 Moderator on at

    I would suggest find the primary key field's value and ignore those while deleting, and you can clear rest of the Fields's value. and your page is closing because the code you have written on OnafterGetrecord trigger, not finding anything, and closing the page.

    Try this.

    Thanks.

  • Suggested answer
    YUN ZHU Profile Picture
    98,059 Super User 2026 Season 1 on at

    Hi, I agree with Nitin. 

    Generally, this kind of document will have Header or Lines, you can clear all Lines, but Header still exists. This way the page won't reopen.

    Or you can refer to the General Journals page,use Worksheet page, and set multiple primary keys to avoid this behavior.

    pastedimage1677026108219v5.png

    pastedimage1677026117585v6.png

    Hope this helps as well.

    Thanks.

    ZHU

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,091 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,032 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 946 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans