web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Conditionally Block Action On List Page AL

(0) ShareShare
ReportReport
Posted on by 1,165

Hi All,

I'm still on my mission to get approvals working with additional block on printing, which I've done on the purchase order page. However I'm unsure how we can block documents from printing based on the document status on list page  - as I'd assume you have to pass selected records  from the list page and check. Bit tricky

Thanks

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,096 Super User 2025 Season 2 on at

    Please search for setselectionfilter

    docs.microsoft.com/.../setselectionfilter-function

  • Anita75 Profile Picture
    1,165 on at

    Thanks, Tried below code but it doesn't work when selecting multiple records for printing. For example below tries to block print when status is open. If I select 2 records when the first only open then loop exist after the first and doesn't print second which is say released:

       begin

           CurrPage.SETSELECTIONFILTER(Rec);

           if rec.FindSet() then

               repeat

                   If Rec.Status = Rec.Status::Open then

                       Error('Order status open cannot be printed %1', Rec."No." + FORMAT((Rec.Status)))

                   else

                       Rec.PrintRecords(true);

               until Rec.Next() = 0;

       end;

    Other issue is after this runs on print action list page is filtered to selected.  How do we show all records as before after the action?

  • Suggested answer
    Suresh Kulla Profile Picture
    50,255 Super User 2025 Season 2 on at

    You need to create a new variable, looks like you are using the Rec. Try this 

     action(PrintSelect)
    {
         ApplicationArea = Basic, Suite;
        Caption = 'Select Records';
        Image = SelectEntries;
        Promoted = true;
        PromotedCategory = Process;
    
        trigger OnAction()
        var
            PurchHeader: Record "Purchase Header";
        begin
            CurrPage.SetSelectionFilter(PurchHeader);
            if PurchHeader.FindSet then
                repeat
                    Message(PurchHeader."No.")
                until PurchHeader.Next = 0;
        end;
    }

  • Anita75 Profile Picture
    1,165 on at

    Thanks Tried it but still not working when you are selecting multiple records:

                   trigger OnAction()

                   var

                       PurchHeader: Record "Purchase Header";

                   begin

                       CurrPage.SETSELECTIONFILTER(PurchHeader);

                       if PurchHeader.FindSet() then

                           repeat

                               If PurchHeader.Status = PurchHeader.Status::Open then

                                   Error('Order status open cannot be printed %1', PurchHeader."No." + FORMAT((PurchHeader.Status)))

                           // else

                           //     PurchHeader.PrintRecords(true);

                           until PurchHeader.Next() = 0;

                   end;

  • Suggested answer
    Suresh Kulla Profile Picture
    50,255 Super User 2025 Season 2 on at

    Anita,

    What is not working the print process ? Are you trying to print all the selected released orders ?

  • Anita75 Profile Picture
    1,165 on at

    Problem is say in the above example if select 2 POs, first one Open and the second Released, and then hit Print, print action blocked on the Open PO and code exit. Released PO does not get to printed

  • Suggested answer
    Suresh Kulla Profile Picture
    50,255 Super User 2025 Season 2 on at

    Well that's how you added the condition in your code, the Error Action will stop all the processing if you want to print only Released then you should remove Error and add a condition like this

    iff PurchHeader.Status = PurchHeader.Status::Releaed then

       PurchHeader.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…

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,090 Moderator

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,090 Moderator

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,277 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans