web
You’re offline. This is a read only version of the page.
close
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

DELETE Multiple Sales Lines using API

(0) ShareShare
ReportReport
Posted on by 3,013

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.
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    95,640 Super User 2025 Season 2 on at

    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

  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    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

  • Verified answer
    Ghetz Profile Picture
    3,013 on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,577

#2
YUN ZHU Profile Picture

YUN ZHU 888 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 778 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans