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...
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
    414 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
    133 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

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

#2
YUN ZHU Profile Picture

YUN ZHU 960 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans