Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

Prevent deletion of item from D365 BC and insert failed response into Integration Logs table

Posted on by 241
When an item is deleted in Business Central, I trigger a call to a third-party API to delete the corresponding item in the third-party application. Additionally, I maintain integration logs to record whether the API call was successful, resulted in an error, or generated a warning.

trigger OnAfterDelete()
    var
        ABC: Codeunit ABC;
    begin
        ABC.DeleteItemFrom3rdPatyApp(Rec./No./);
    end;

I make this API call within the OnAfterDelete trigger in the Item table extension. However, if an error occurs from the third-party application, I need to insert the error response into the Integration Logs table and also need to show that error to the user in the web client. The challenge here is that when an error occurs, Business Central automatically rolls back all transactions, including the insertion of the error response into the Integration Logs table. 

When I use the Commit() function, it also deletes the corresponding item from BC.

My goal is to prevent the deletion of the item from Business Central in the OnAfterDelete() trigger while still being able to insert the failed response into the Integration Logs table. If anyone could provide guidance on how to achieve this functionality, I would greatly appreciate it. Thank you for taking the time to read this.
  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 68,842 Super User 2024 Season 2 on at
    Prevent deletion of item from D365 BC and insert failed response into Integration Logs table
    Hi, I don't know exactly what is implemented in the 3rd party app, but is it possible without throwing an error in BC, like using Try methods/functions.
     
    Hope this gives you some tips.
     
    Thanks
    ZHU

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,353 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,251 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans