Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

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

Posted on by 2,203 Super User 2024 Season 1

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!

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,696 Super User 2024 Season 2 on at
    RE: How to prevent a page trigger from executing when clearing all records?

    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

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to prevent a page trigger from executing when clearing all records?

    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.

  • Govinda Kumar Profile Picture
    Govinda Kumar 2,203 Super User 2024 Season 1 on at
    RE: How to prevent a page trigger from executing when clearing all records?

    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
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to prevent a page trigger from executing when clearing all records?

    Hi,

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

    Thanks.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans