Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Event Subscriber Item Trigger behavior unexpected with "Qty. on Sales Order"

(0) ShareShare
ReportReport
Posted on by 30

I have created an event subscribers on the Item table and another on the   'Qty. on Sales Order'    field of the Item table. See below snippets: 

[EventSubscriber(ObjectType::Table, Database::Item, 'OnAfterValidateEvent', 'Qty. on Sales Order', false, false)]
*trivial function code here*
[EventSubscriber(ObjectType::Table, Database::Item, 'OnAfterModifyEvent', '', false, false)]
*trivial function code here*

My issue is when I create a new sales or purchase line, my Item event subscribers are not fired. The reason I believe they should be is because Qty. on Sales Order is updated on the item every time I create a new sales line with that item. I have confirmed this by checking the data before and after creating a sales line. 

Does business central only fire event subscribers for manual edits such as changing the description or display name of an item? or a better question,

Does business central fire event subscribers for readonly value changes such as "Qty. on Sales Order" ?

*Note: The event subscriber works well for everything I need except for when "Qty. on Sales Order" and "Qty. on Purch Order" change. For example when I update the item header it will trigger the item table subscriber. I need to know when those two fields on an item change.

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 77,925 Super User 2025 Season 1 on at
    RE: Event Subscriber Item Trigger behavior unexpected with "Qty. on Sales Order"

    Hi, This is because the field 'Qty. on Sales Order' you subscribe to is a FlowField. As you might know, the value of FlowField do not actually exist in the table, but are recalculated when the page is opened. So OnAfterValidateEvent has no effect on it.
    I think you need to change your solution. As Nitin mentioned, you should add your all codes to the events on sales lines.

    pastedimage1654220205752v1.png

    Hope this helps as well.

    Thanks.

    ZHU

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,273 Moderator on at
    RE: Event Subscriber Item Trigger behavior unexpected with "Qty. on Sales Order"

    Hi JaredT ,

    Not sure what you are looking for, but If you are modifying or changing the qty. on Sales or Purchase line, it will never calls the  trigger of any Item, instead if you want to check how much the qty. is on Item."Qty. on Sales Order". you can write below code.

    OnAfterValidateEvent "Quantity" on Sales Line.

    if Item.get(SalesLine."No.") then

    begin

     item.calcfields("Qty. on Sales Order");

     Message('%1',Item."Qty. on Sales Order");

    end;

    You can replace the above message function with your custom statements according to your requirement.

  • JaredT Profile Picture
    JaredT 30 on at
    RE: Event Subscriber Item Trigger behavior unexpected with "Qty. on Sales Order"

    Hi Nitin, thank you for getting back. I have added Message() calls at the very beginning of my Item modify trigger.

    I can confirm the trigger message works when changing the item header description OnAfterModifyEvent.

    However when changing quantity numbers in a sales line it does not trigger the item table OnAfterModifyEvent.

    Are there any other things I can check for or ways to troubleshoot this?

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,273 Moderator on at
    RE: Event Subscriber Item Trigger behavior unexpected with "Qty. on Sales Order"

    Hi JaredT ,

    Qty. on Sales Order and Qty. on Purch. Order field are Flowfields which automatically calculates when you put this item on Sales and Purchase line respectively, and flowFields does not fire any Validate event, and that is the reason why your OnafterValidateEvent fire.

    But your event [EventSubscriber(ObjectType::Table, Database::Item, 'OnAfterModifyEvent', '', false, false)] should run perfectly.

    Thanks.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans