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

Block UnApproved Purch Order Printing

(0) ShareShare
ReportReport
Posted on by 1,165

Hi All,

I'm trying to stop un-approved purchase order from being printed via code. And tried below code but doesn't seem to work:

actions
    {
        modify("&Print")
        {
            Caption = 'PO Print';
            trigger OnBeforeAction()
            var
                PurchaseHeader: Record "Purchase Header";

            begin
                IF PurchaseHeader.Status <> PurchaseHeader.Status::"Pending Approval" THEN Begin
                    PurchaseHeader := Rec;
                    CurrPage.SetSelectionFilter(PurchaseHeader);
                    PurchaseHeader.PrintRecords(true);
                End
                else
                    ERROR('Purchase order has not been approved');

            end;
I have the same question (0)
  • Bilal Haider Profile Picture
    442 on at

    Hi,

    For which page have you written this code. Look like you have written it for List page. What is the problem you are getting. Can you elaborate?

  • Suggested answer
    JAngle Profile Picture
    150 on at

    It’s the placement of the error that might need changing. The selectionfilter is fine for the print command. I think you should do a if findset on the filter criteria before doing the print. The selection filter will have many records to loop through so the error command in isolation probably doesn’t pick up on that. There are more sophisticated error trapping methods if passed to a relevant codeunit

  • Anita75 Profile Picture
    1,165 on at

    This worked:

               begin

                   PurchaseHeader := Rec;

                   IF PurchaseHeader.Status = PurchaseHeader.Status::"Pending Approval" THEN

                       ERROR('Purchase order has not been approved')

                   else

                       CurrPage.SetSelectionFilter(PurchaseHeader);

                   PurchaseHeader.PrintRecords(true);

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,055 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,063 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,014 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans