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

Community site session details

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

Printing the Job Card Automatically by Clicking the "OK" Button

(2) ShareShare
ReportReport
Posted on by 2,512
Hi:
 
I totally misread the need on my code.
 
I want to print the Job Card report when the "OK" button residing within the "Refresh Production Order" screen is clicked in a Released Production Order -- not when the Released Production Order button itself is pressed.
 
How do I modify this code to accomplish that?
 
Thanks!
 
John
 
pageextension 50101 "ProdOrderExt" extends "Released Production Order"
{
    actions
    {
        addlast(Processing)
        {
            action(PrintJobCard)
            {
                Caption = 'Print Job Card';
                Image = Print;
                trigger OnAction()
                var
                    ProdOrderRec: Record "Production Order";
                    JobCardReport: Report "Prod. Order - Job Card";
                    OutputFile: File;
                    OutputFilePath: Text;
                    TempBlob: Codeunit "Temp Blob";
                    OutStream: OutStream;
                begin
                    // Call original behavior
                    CurrPage.Update(); // Simulate Refresh action or use page action if needed
 
                    // Get the current Production Order
                    Rec.TestField("No.");
                    ProdOrderRec.Get(Rec."No.");
 
                    // Prepare to save report to PDF
                    TempBlob.CreateOutStream(OutStream);
                    // Use a filter string as the second argument
                    Report.SaveAs(Report::"Prod. Order - Job Card", 'No.=' + Rec."No.", ReportFormat::Pdf, OutStream);
 
                    // Save to file system or stream to download — for now, simulate download
                    OutputFilePath := 'JobCard_' + Rec."No." + '.pdf';
 
                    // Create an InStream from the TempBlob and download the file
                    TempBlob.CreateInStream(InStr);
                    DownloadFromStream(InStr, 'Job Card', 'PDF Files|*.pdf', '', OutputFilePath);
                end;
            }
        }
    }
    var
        InStr: InStream;
}
I have the same question (0)
  • JE-20081519-0 Profile Picture
    2,512 on at
    Printing the Job Card Automatically by Clicking the "OK" Button
    Thank you!  I have always appreciated your help/
     
    Is there any way that you can give me some hints on the code, please?  :)
     
    John
  • JE-20081519-0 Profile Picture
    2,512 on at
    Printing the Job Card Automatically by Clicking the "OK" Button
    The "OnAfterRefreshProdOrder" event doesn't exist.  Any other ideas?
     
    Thanks, so much!
     
    John
  • JE-20081519-0 Profile Picture
    2,512 on at
    Printing the Job Card Automatically by Clicking the "OK" Button
    Hi Sohail:
     
    If you can get something for me by beginning of next week, I would be most thankful!
     
    And, thank you, for offering!
     
    John
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,503 Super User 2025 Season 2 on at
    Printing the Job Card Automatically by Clicking the "OK" Button
    Typically, the Refresh action triggers codeunit 5407 "Prod. Order Status Management" or some production-specific codeunit.
     
    I hope below can help
     
    codeunit 50102 "JobCardAfterRefreshHandler"
    {
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Prod. Order Status Management", 'OnAfterRefreshProdOrder', '', true, true)]
        local procedure AfterRefreshProdOrder(ProdOrderNo: Code[20])
        var
            ProdOrderRec: Record "Production Order";
            TempBlob: Codeunit "Temp Blob";
            OutStream: OutStream;
            InStream: InStream;
            OutputFilePath: Text;
        begin
            // Validate Production Order exists
            if not ProdOrderRec.Get(ProdOrderNo) then
                exit;
            // Generate Job Card PDF
            TempBlob.CreateOutStream(OutStream);
            Report.SaveAs(Report::"Prod. Order - Job Card", 'No.=' + ProdOrderNo, ReportFormat::Pdf, OutStream);
            TempBlob.CreateInStream(InStream);
            OutputFilePath := 'JobCard_' + ProdOrderNo + '.pdf';
            DownloadFromStream(InStream, 'Job Card', 'PDF Files|*.pdf', '', OutputFilePath);
        end;
    }
     
     
    Thanks
    Ramesh
     
     
  • Suggested answer
    YUN ZHU Profile Picture
    90,113 Super User 2025 Season 2 on at
    Printing the Job Card Automatically by Clicking the "OK" Button
    Hi, If you mean clicking the OK button in the report below, you need to expand the report, not the page.
     
    For example,
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    Sohail Ahmed Profile Picture
    10,983 Super User 2025 Season 2 on at
    Printing the Job Card Automatically by Clicking the "OK" Button
    i tried to find some built in example but i was not able to find exact AL code reference for you. if this is not urgent then i can provide you example code after testing on my sandbox at weekend 
  • JE-20081519-0 Profile Picture
    2,512 on at
    Printing the Job Card Automatically by Clicking the "OK" Button
     
    Could you please point me to some resources where I can learn how to do this? 
     
    I'm a novice at AL.
     
    Thanks!
     
    John
  • Suggested answer
    Sohail Ahmed Profile Picture
    10,983 Super User 2025 Season 2 on at
    Printing the Job Card Automatically by Clicking the "OK" Button
    the Job Card report to print automatically when the “OK” button is clicked inside the "Refresh Production Order" request page, not just from the Released Production Order page action.
     
    Here's the clarification: the "OK" button on a request page (e.g. Refresh Production Order) is handled internally by a report or codeunit, not something you can hook into directly using a pageextension on "Released Production Order". Your current code adds a separate action on the Released Production Order page — not what you're asking for.
     
    What you actually need:
     
    If you want the Job Card report to automatically print after the "OK" button is clicked (i.e., after the Refresh Production Order logic runs), you’ll need to subscribe to the event that runs after the refresh logic completes. Typically, this is inside codeunit 99000787 "Production Order Management", possibly around methods like RefreshProductionOrder.
     
    So:
     
    Find the correct event publisher (likely OnAfterRefreshProductionOrder or similar).
     
    Create an event subscriber that triggers the Job Card report using the production order number as a filter.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,678 Super User 2025 Season 2

#2
Sumit Singh Profile Picture

Sumit Singh 2,635

#3
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 2,210

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans