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...
Unanswered

How to reopen sales order from sales lines in code

(0) ShareShare
ReportReport
Posted on by 403

Hi,

We need to allow (in some circumstances) for a sales order to over ship. To do so, we need to be able to update the quantity automatically when the qty. to ship entered by the user is greater than what's left to ship. The order is already released and the user should not have to reopen it manually, change the quantity and release it again. All this process must be transparent to the user.

With the new A/L language, I'm having a hard time figuring out how to achieve this. I subscribed to the event OnValidateQtyToShipAfterInitQty from the Sales Line table where I'm adding code to go update the quantity. This needs to be validated as the amounts must be updated as well. But the validation is checking if the sales order is open which it is not. I tried calling the SuspendStatusCheck function to skip the validation but it's then failing in the UpdateAmounts function. I tried reopening the order in my event subscriber, but since the sales header is not passed as a variable, once the validation goes to the UpdateAmounts function, the GetSalesHeader function is called and the status is back to released. Then I tried to also subscribed to the OnBeforeUpdateAmounts event and set the IsHandled to true so the base code is skipped. I copied the code from base and skipped the  error message on the status, but for some reason, when I call the UpdateVATAmounts and InitOutstandingAmounts function from that event subscriber, the base code is not executed at all. So the quantities are updated properly but not the amounts and taxes

What am I missing? Any help would be greatly appreciated.

-Julie

I have the same question (0)
  • Daniel Rimmelzwaan Profile Picture
    3,485 on at

    The "Reopen" function in the ReleaseSalesDocument codeunit does take the SalesHeader by reference.

    pastedimage1603399971922v1.png

    The GetSalesHeader function in the Sales Line table does not actually get the sales if it already has it. You'll have to get it yourself after re-opening it. Yould experiment with subscribing to the "OnAfterReopenSalesDoc" event in the Release codeunit and see if you can set your Sales Header variable there. You'd have to make it a global variable, which is not always recommended.

  • Juliem Profile Picture
    403 on at

    Thank you for your answer

    Maybe I'm missing the point but I don't understand what your are suggesting

    I need to subscrive to the OnValidateQtyToShipAfterInitQty event from the Sales Line table, which is what is triggering my logic. I have put the event subscriber into a custom codeunit. Since that event doesn't have the Sales Header as a parameter, I need to declare it as a variable, but then, when my code is over, it goes back to standard NAV code and the modification I made to my variable Sales Header is not transfered to the variable used in the base code.

    I don't know how to fix that issue.

  • Daniel Rimmelzwaan Profile Picture
    3,485 on at

    What I mean is the GetSalesHeader function only goes to the database if the doc type and number are different than what it already has.

    Maybe there is an event that does include the SalesHeader variable so you can pass it back to the SalesLine. Maybe you can reopen the sales doc first and then you do your logic on the line level.

  • Juliem Profile Picture
    403 on at

    I understand what you mean now, but still don't know how I could achieve that.

    I mean, the trigger I need is when the qty. to ship is changed by the user, and the events related to that field don't have the header as a parameter.

  • Daniel Rimmelzwaan Profile Picture
    3,485 on at

    You'll have to figure out a way :)

    The GetSalesHeader function has an OnBeforeGetSalesHeader event that passes both the current Sales Line record and the SalesHeader variable. You could force a Get there, but I'm not sure if it won't be too late there

    You could subscribe to OnAfterValidate and see if you can take care of the requirement there

    You could let the error message stand and make the user reopen the document manually

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

#2
YUN ZHU Profile Picture

YUN ZHU 1,122 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans