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 :
Supply chain | Supply Chain Management, Commerce
Suggested Answer

What is the best event to use when automatically canceling sales lines during order entry

(0) ShareShare
ReportReport
Posted on by 70

Newbie question: We are working on implementing D365 Finance, Commerce, and Supply-Chain Management.  One of the requirements is to automatically cancel any sales line being added to a sales order if the quantity ordered is greater than the quantity available.

I've tried adding event handlers to various SalesLine table events as well as the SalesLine form data source in the SalesTable form, which checks the available quantity and sets the line status to canceled if there isn't enough available.  Nothing I've tried has worked so far... either an error is thrown, or the line status does not change when it should.

Does anyone have any suggestions on the best way to accomplish this?  The main question I have is which event should I subscribe to.  Secondarily, is there a recommended way to modify the sales line record at the time the record is being inserted or updated, and do it in such a way that it doesn't cause problems for the SalesTable form.

Thanks in advance for any advice.

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    I think that canceling a sales line requires more than just setting the status field to Canceled. On the other hand, if the line didn't exist as normal line, what's there to cancel?

    You might succeed by first creating the line and then canceling it right after by using same code that the system runs when canceling an order line via the user interface.

    I'm curious to hear the business requirement that you're trying to solve. Could you share it? Thanks!

  • Daniel J. Zook Profile Picture
    70 on at

    Thanks for the reply.  

    To answer your question about the business requirement, there are a couple scenarios.  One of the typical ones is an item that we no longer replenish.  We want to sell out of our remaining stock, but we do not want any more orders allowed after that.  Setting the "stopped" flag doesn't work, since that prevents it from being sold regardless of in-stock status.

    We have this feature today in R2 with an ISV solution that facilitates call center orders (different from the Call Center in AX was added in R3).  If an item is flagged to not allow back orders, the line item is automatically canceled if the quantity ordered is greater than the quantity available.

    I'm open to suggestion if you have an idea for a better way to accomplish this requirement.

    Thanks again.

  • André Arnaud de Calavon Profile Picture
    305,265 Super User 2026 Season 1 on at

    Hi Daniel,

    Have you checked with the ISV vendor if they have the same solution available for Dynamics 365?

    Instead of automatic cancelling, I would consider a dialog with a warning and let the user then decide to reduce to available or cancel the line.

  • Daniel J. Zook Profile Picture
    70 on at

    Thanks for the suggestions Andre.

    We are not interested in keeping this ISV solution, since the majority of the features from that solution are now native in R3/D365.

    I'll check with the stakeholders re: your suggestion of a dialog instead of automatically canceling.

  • Suggested answer
    Daniel J. Zook Profile Picture
    70 on at

    I wasn't able to make this work exactly the way we hoped, but for now I implemented the following:

    - subscribe to the SalesLine data source, ValidatingWrite event

    - check the availability and product lifecycle state, and if it doesn't allow back orders and there isn't enough available, show an error message and set the event args "cancel" to true.

    var args = e as FormDataSourceCancelEventArgs;

    args.cancel(true);

    This setup prevents "end of life" items from being sold beyond the inventory availability in the sales order form.

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 143 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 102 Super User 2026 Season 1

#3
Laurens vd Tang Profile Picture

Laurens vd Tang 96 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans