Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

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

(0) ShareShare
ReportReport
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 76,221 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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,904 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans