Skip to main content

Notifications

Announcements

No record found.

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

DELETE Multiple Sales Lines using API

(0) ShareShare
ReportReport
Posted on by 2,983

We have a Business Central 21 Integration, that in certain business cases, needs to delete all lines from a Sales Order.

We have tried using the API, but there is a big performance issue, asi you need to first retrieve the GUID for each line, and then call the DELETE action in the API to delete each of the lines.This takes almost 1 second per call, and when we have a big sales order, user can be waiting for 30 seconds , which is just unacceptable.

I can't see in the documentation, any way to delete multiple lines in batch, using the API.

If I try using a filter, we get an error; for example calling DELETE using this URL

Test-2019:7048/BC210/api/v1.0/companies(afe434c7-6e8b-ed11-b34e-000c29584daa)/salesOrders(61b7a217-0aa6-ed11-b35e-000c29584daa)/salesOrderLines?$filter=documentId eq 61b7a217-0aa6-ed11-b35e-000c29584daa

throws an error 

"DELETE\" requests for \"salesOrderLines\" of type Edm \"Collection\" not allowed
Do we have any other option to batch delete all lines in a order?
For the moment, we are using out least favourite approach, which is to delete the lines with direct SQL. As new extensions can be installed at anytime, we will need to take this into account, as for each extension you will have an additional Sales Line table. I'm not aware that CASCADE deletes have been enabled for business central extension SQL server tables.
Example
select * from [dbo].[test$Sales Line$437dbf0e-84ff-417a-965d-ed2bb9650972] A
where A.[Document No_] = '101168' and A.[Line No_] = 10000

select * from [dbo].[test$Sales Line$4662cf56-ea5f-4736-a0b8-87973ca91053] B
where B.[Document No_] = '101168' and B.[Line No_] = 10000

delete from [dbo].[test$Sales Line$437dbf0e-84ff-417a-965d-ed2bb9650972]
where [Document No_] = '101168' and [Line No_] = 10000
The delete statement, will not trigger a CASCADE delete on the the other Sales Line tables.
  • Verified answer
    Ghetz Profile Picture
    Ghetz 2,983 on at
    RE: DELETE Multiple Sales Lines using API

    yzhums DAnny3211  Thanks! both options are very interesting. Will implement one of them for sure.

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,274 Super User 2024 Season 1 on at
    RE: DELETE Multiple Sales Lines using API

    Hi

    you could also think about exposing a codeunit as an API and put the logic of your deletion in it. you also have the ability to pass parameters to it that would be your possible filters

    www.kauffmann.nl/.../

    DAniele

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 75,595 Super User 2024 Season 2 on at
    RE: DELETE Multiple Sales Lines using API

    Hi, hope the information below can give you some hints.

    Batch calls with Business Central APIs

    https://www.kauffmann.nl/2020/12/18/batch-calls-with-business-central-apis-1-basic-operation/

    https://www.kauffmann.nl/2021/01/06/batch-calls-with-business-central-apis-3-tips-and-tricks/

    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! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans