Skip to main content

Notifications

Community site session details

Community site session details

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

Event Subscriber firing multiple times for Customer table

(1) ShareShare
ReportReport
Posted on by

Hi,

I have created an Event subscriber on the "Customer" table in a codeunit. In my subscriber procedure i send a payload to an external server with information from the record that raised the event. My issue is that when i raise the "OnAfterInsertEvent", my server receives 2 payloads for the insert event and almost 6 payloads for a modify event.

Example Event Subscriber: 

* INSERT MODIFY and DELETE events all look the same except for the 'insert' hardcoded, each are 'insert','modify','delete' respectively. also the 'OnAfter<event>Event' is different respectively.

  [EventSubscriber(ObjectType::Table, Database::Customer, 'OnAfterInsertEvent', '', true, true)]
  local procedure CustomersOnAfterInsertEvent(var Rec: Record Customer; RunTrigger: Boolean)
  var
    payload: JsonObject;
    payload_text: Text;
    data: JsonObject;
  begin
    data.Add('id', Rec.SystemId);
    payload := buildPayload.StandardPayload(data);
    buildPayload.StandardRequest( payload);
  end;

Here is an example of the payload i receive 2 of.

{
table: 'Customer',
data: { id: '05F41CA7-4FEB-EC11-82F8-0022482AD7A0' },
trigger: 'insert',
}

Here is an example of the payload i receive 6 or more of.

{
table: 'Customer',
data: { id: '05F41CA7-4FEB-EC11-82F8-0022482AD7A0' },
trigger: 'modify',
}

I would like to think that my logic is correct because these exact event subscribers work 100% perfectly fine for the other tables i have them on 'Sales Orders' being another one. This issue only occurs for the Customers table which is why i believe it may have to do with how msbc handles event subscribers. 

Could this have anything to do with what MSBC does internally that would fire the event subscriber multiple times.

Any information on how event subscribers are handled (especially the customer table) would be useful for my understanding. 

  • Community Member Profile Picture
    on at
    RE: Event Subscriber firing multiple times for Customer table

    Thank you for responding, I isolated the the subscriber event to a different test company and the same happened. I am sure that this is the only event subscriber on the customers table. Also, i went back to double check and for some reason 'Sales Header' on insert event also returns 2 payloads indicating the event fired twice. I did notice something interesting though, when i isolated the customer subscriber to a different company as soon as i clicked the +New button in MSBC i got an insert payload. Then when i added the customer number and name i got a modify payload. Any ideas or thoughts on this weird behaviour? If you're interested, to recreate just add a subscriber to the customers table like i show above and send that to an external api that just console logs. Thats literally all i have currently.

  • Suggested answer
    Nitin Verma Profile Picture
    21,544 Moderator on at
    RE: Event Subscriber firing multiple times for Customer table

    Hi ,

    Few questions I have, are you are only person in BC creating new customer? Can you please check if there is any other customization which is creating new customer on a particular case? Also please try to run the same case in new demo company

    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,101 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans