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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Approval workflow Error

(3) ShareShare
ReportReport
Posted on by 65
HI Community, 
 
I have created a approval workflow for release sales orders. This workflow works in version V25 but when the approval workflow is triggerd in V26 I will get an error: 
 
Error: 
Status must be equal to Open in Sales Header: Document Type = Order, No. = V25080017. The current value is Pending Approval (wacht op goedkeuring).

AL-caalstack: 
"Sales-Calc. Discount"(CodeUnit 60).OnRun(Trigger) line 8 - Base Application by Microsoft version 26.3.36158.37115
"Release Sales Document"(CodeUnit 414).Code line 54 - Base Application by Microsoft version 26.3.36158.37115
"Release Sales Document"(CodeUnit 414).OnRun(Trigger) line 6 - Base Application by Microsoft version 26.3.36158.37115
"Release Sales Document"(CodeUnit 414).PerformManualCheckAndRelease line 27 - Base Application by Microsoft version 26.3.36158.37115
"Workflow Response Handling"(CodeUnit 1521).ReleaseDocument line 32 - Base Application by Microsoft version 26.3.36158.37115
"Workflow Response Handling"(CodeUnit 1521).ExecuteResponse line 29 - Base Application by Microsoft version 26.3.36158.37115
"Workflow Management"(CodeUnit 1501).ExecuteResponses line 32 - Base Application by Microsoft version 26.3.36158.37115
"Workflow Management"(CodeUnit 1501).ExecuteQueuedEvents line 21 - Base Application by Microsoft version 26.3.36158.37115
"Workflow Management"(CodeUnit 1501).ExecuteResponses line 40 - Base Application by Microsoft version 26.3.36158.37115
"Workflow Management"(CodeUnit 1501).HandleEventWithxRec line 27 - Base Application by Microsoft version 26.3.36158.37115
"Workflow Management"(CodeUnit 1501).HandleEvent line 2 - Base Application by Microsoft version 26.3.36158.37115
"Workflow Event Handling"(CodeUnit 1520).RunWorkflowOnSendSalesDocForApproval line 2 - Base Application by Microsoft version 26.3.36158.37115
"Approvals Mgmt."(CodeUnit 1535).OnSendSalesDocForApproval(Event) line 2 - Base Application by Microsoft version 26.3.36158.37115
"Sales Order"(Page 42)."SendApprovalRequest - OnAction"(Trigger) line 5 - Base Application by Microsoft version 26.3.36158.37115
 
 
I did some debugging and see that this code is added in Business Central V26. What is this code trying to do? Because the Sales Header (Rec) status is Open, but the TempSalesHeader.status is Pending approval. 
 
Kind regards, 
Youri 
I have the same question (0)
  • Suggested answer
    Sumit Singh Profile Picture
    11,757 Super User 2026 Season 1 on at
     Issue
    The error:
    "Status must be equal to Open in Sales Header…"
    is triggered because the TempSalesHeader.Status is still Pending Approval, even though the main Rec.Status is Open.
     What the New Code in V26 Is Doing
    In Codeunit 60 – Sales-Calc. Discount, the added logic is:
    TempSalesHeader.Get(Rec."Document Type", Rec."Document No.");
    if TempSalesHeader.Status = TempSalesHeader.Status::"Pending Approval" then
        if DimMgt.CheckDimIDSelfStatus(TempSalesHeader."Sell-to Customer No.") then begin
            TempSalesHeader.Status := TempSalesHeader.Status::Open;
            UpdateHeader := true;
        end;
    Breakdown:
    • It retrieves the Sales Header into a temporary record (TempSalesHeader).
    • Checks if its status is Pending Approval.
    • If so, and if the dimension check passes, it sets the status to Open and flags UpdateHeader := true.
    Why the Error Still Occurs
    Even though the code attempts to reset the status to Open, the error occurs because:
    • The workflow engine is trying to release the document while it's still in Pending Approval.
    • The status change in TempSalesHeader is not committed before the release logic runs.
    • The release logic (Codeunit 414) expects the document to be in Open status before it starts processing.
    Recommended Fix or Workaround
    Option 1: Update Workflow Response Logic
    Ensure that the workflow response:
    • Changes the status to Open before calling the release logic.
    • You may need to customize Codeunit 1521 (Workflow Response Handling) to explicitly update the status before calling ReleaseDocument.
    Option 2: Pre-Release Status Validation
    Add a validation step in your workflow:
    • Before executing ReleaseDocument, check and update the status of the Sales Header to Open.
    Option 3: Patch or Override the Logic
    If you're customizing the base app:
    • Override the logic in Sales-Calc. Discount or Release Sales Document to ensure the status is properly synchronized between Rec and TempSalesHeader.
    What the Code Is Doing
    The new logic in V26 attempts to reset the status of a Sales Header from "Pending Approval" to "Open" using:
    TempSalesHeader.SetLastSelfStatus(TempSalesHeader.Status::Open);
    UpdateHeader := true;
    However, this change is made on a temporary record (TempSalesHeader), and unless explicitly updated back to the database, it does not persist—leading to the error when the release logic checks the actual record.
    How to Patch the Logic
    To ensure the status change is committed before the release logic runs, you can patch the logic in one of two ways:
    Option 1: Patch Codeunit 60 – Sales-Calc. Discount
    Add a Modify(true) after setting the status:
    TempSalesHeader.Get(Rec."Document Type", Rec."Document No.");
    if TempSalesHeader.Status = TempSalesHeader.Status::"Pending Approval" then begin
        TempSalesHeader.SetLastSelfStatus(TempSalesHeader.Status::Open);
        TempSalesHeader.Modify(true); //  Persist the change
        UpdateHeader := true;
    end;
    This ensures the status change is saved to the database before the release logic runs.
    Option 2: Patch Codeunit 414 – Release Sales Document
    If you prefer to handle it closer to the release logic, you can add a pre-check in PerformManualCheckAndRelease:
    SalesHeader.Get("Document Type", "No.");
    if SalesHeader.Status = SalesHeader.Status::"Pending Approval" then begin
        SalesHeader.SetLastSelfStatus(SalesHeader.Status::Open);
        SalesHeader.Modify(true); // Persist the change
    end;
     This ensures that any document in "Pending Approval" is reset before release.
     Important Notes
    • Ensure that this patch does not conflict with your approval workflow logic. You may want to restrict it to cases where the workflow has completed.
    • Consider adding a custom field or flag to indicate that the document is safe to release (e.g., ApprovalCompleted = true).
    Note: This response was created in collaboration with Microsoft Copilot to ensure clarity and completeness. I hope it helps to some extent.
    Mark the Answer as Verified if this is Helpful.
     
  • Manish Sharma Profile Picture
    101 on at
    Seems a bug, that line of code is not available in v24 nor in v25.
  • Verified answer
    YUN ZHU Profile Picture
    99,055 Super User 2026 Season 1 on at
    Hi, This is a standard bug I saw mentioned in the BC Yammer group last month.
    It should have been resolved in BC26.4, which was released two days ago.
     
    Hope this info helps.
    Thanks.
    ZHU

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

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 1,926 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,158 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 533 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans