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

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;
  • Anita75 Profile Picture
    1,159 on at
    RE: Block UnApproved Purch Order Printing

    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);

  • Suggested answer
    JAngle Profile Picture
    63 on at
    RE: Block UnApproved Purch Order Printing

    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

  • Bilal Haider Profile Picture
    234 on at
    RE: Block UnApproved Purch Order Printing

    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?

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,999 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,831 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans