Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Conditionally Block Action On List Page AL

Posted on by 1,159

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

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Conditionally Block Action On List Page AL

    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)

  • Anita75 Profile Picture
    Anita75 1,159 on at
    RE: Conditionally Block Action On List Page AL

    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
    Suresh Kulla 43,745 on at
    RE: Conditionally Block Action On List Page AL

    Anita,

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

  • Anita75 Profile Picture
    Anita75 1,159 on at
    RE: Conditionally Block Action On List Page AL

    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
    Suresh Kulla 43,745 on at
    RE: Conditionally Block Action On List Page AL

    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
    Anita75 1,159 on at
    RE: Conditionally Block Action On List Page AL

    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
    Mohana Yadav Profile Picture
    Mohana Yadav 59,137 Super User 2024 Season 2 on at
    RE: Conditionally Block Action On List Page AL

    Please search for setselectionfilter

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans