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;
  • Bilal Haider Profile Picture
    487 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
    161 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 664 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 446 Super User 2026 Season 2

#3
Teagen Boll Profile Picture

Teagen Boll 282 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans