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

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,708 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,708 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
    95,729 Super User 2025 Season 2 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

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

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans