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

how to undo a finished production order

(1) ShareShare
ReportReport
Posted on by
Hello, I want to undo a posted production order, automatically with code, this is my code but doesn't work : 
procedure UndoPostedProductionOrder(ProdOrderNo_P: Code[20]; ProdOrderLines_P: Integer; Qty_P: Decimal; BinCode: Code[20]; MobileUser_P: Code[10]): Text
    var
        ProdOrderLine: Record "Prod. Order Line";
        ProdOrder: Record "Production Order";
        ItemJournalLine: Record "Item Journal Line";
        MfgSetup: Record "Manufacturing Setup";
        ForReservEntry_L: Record "Reservation Entry";
 
        ProductionJrnlMgt: Codeunit "Production Journal Mgt";
        ItemJnlPostBatch: Codeunit "Item Jnl.-Post Batch";
        CreateReservEntry_L: Codeunit "Create Reserv. Entry";
 
        ProgressBar: Dialog;
        GeneratingJnlLinesMsg: Label 'Generating journal lines for reversal.';
        Status_L: Enum "Reservation Status";
        ToTemplateName: Code[10];
        ToBatchName: Code[10];
 
        ErrorOrderLineNotExist: Label 'Prod. Order Line does not exist';
        ErrorOrderNotExist: Label 'Production Order does not exist';
    begin
        if not ProdOrderLine.Get(ProdOrderLine.Status::Released, ProdOrderNo_P, ProdOrderLines_P) then
            Error(ErrorOrderLineNotExist);
 
        if not ProdOrder.Get(ProdOrder.Status::Released, ProdOrderNo_P) then
            Error(ErrorOrderNotExist);
 
        MfgSetup.Get();
        ProductionJrnlMgt.SetTemplateAndBatchName();
        ProductionJrnlMgt.InitSetupValues();
 
        ProgressBar.Open(GeneratingJnlLinesMsg);
 
        ProductionJrnlMgt.DeleteJnlLines(ToTemplateName, ToBatchName, ProdOrder."No.", ProdOrderLines_P);
 
        ProductionJrnlMgt.CreateJnlLines(ProdOrder, ProdOrderLines_P);
 
        ItemJournalLine.Reset();
        if StrLen(UserId) > 10 then
            ItemJournalLine.SetRange("Journal Batch Name", CopyStr(UserId, 1, 10))
        else
            ItemJournalLine.SetRange("Journal Batch Name", UserId);
        ItemJournalLine.SetRange("Order Type", ItemJournalLine."Order Type"::Production);
        ItemJournalLine.SetRange("Order No.", ProdOrderNo_P);
        ItemJournalLine.SetRange("Order Line No.", ProdOrderLines_P);
 
        if ItemJournalLine.FindSet() then begin
            repeat
                // ItemJournalLine.Validate("Stop Time", 0);
                // ItemJournalLine.Validate("Setup Time", 0);
                // ItemJournalLine.Validate("Bin Code", BinCode);
                // ItemJournalLine.Modify();
                if (ItemJournalLine."Entry Type" = ItemJournalLine."Entry Type"::Output) then begin
                    ItemJournalLine.Validate(Quantity, -Qty_P);
                    ItemJournalLine.Modify();
                end else if (ItemJournalLine."Entry Type" = ItemJournalLine."Entry Type"::Consumption) then begin
                    ItemJournalLine.Validate("Entry Type", ItemJournalLine."Entry Type"::"Positive Adjmt.");
                    ItemJournalLine.Validate(Quantity, Qty_P);
                    ItemJournalLine.Modify();
                    CreateReservEntry_L.SetDates(0D, ForReservEntry_L."Expiration Date");
                    CreateReservEntry_L.CreateReservEntryFor(
                                  Database::"Item Journal Line", ItemJournalLine."Entry Type".AsInteger(),
                                  ItemJournalLine."Journal Template Name", ItemJournalLine."Journal Batch Name", 0, ItemJournalLine."Line No.", ItemJournalLine."Qty. per Unit of Measure",
                                  Qty_P, Qty_P * ItemJournalLine."Qty. per Unit of Measure", ForReservEntry_L);
                    CreateReservEntry_L.CreateEntry(
                   ItemJournalLine."Item No.", ItemJournalLine."Variant Code", ItemJournalLine."Location Code", '', 0D, 0D, 0, Status_L::Surplus);
                end;
 
            until ItemJournalLine.Next() = 0;
        end;
 
        ItemJnlPostBatch.Run(ItemJournalLine);
 
        ProgressBar.Close();
 
        exit('');
    end;
I have the same question (0)
  • Suggested answer
    Ben Baxter Profile Picture
    6,428 Super User 2025 Season 2 on at
    how to undo a finished production order
    I would like to suggest against this customization.  There are a lot of moving pieces that happen when a Production Order is finished.  This is why Microsoft doesn't allow you to Reopen the Finished Prod. Order.
     
    There are many ways suggested on the forum about how to make corrective entries when a mistake is made and the Prod. Order is Finished.  If you're going to automate something, I would automate those steps instead.
     
    Just my 2 cents.
     
    Best Regards,
    Ben Baxter
    Accent Software Inc
  • Gerardo Rentería García Profile Picture
    23,855 Most Valuable Professional on at
    how to undo a finished production order
    Hi
    As mentioned by our colleague, here are a couple of links that could also help you with this requirement.
    Best
    GR
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,922 Super User 2025 Season 2 on at

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,163

#2
OussamaSabbouh Profile Picture

OussamaSabbouh 1,908

#3
YUN ZHU Profile Picture

YUN ZHU 1,878 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans