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 2,999

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
    2,999 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
    9,276 Moderator 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
    82,589 Super User 2025 Season 1 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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 290 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 196

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 156 Most Valuable Professional

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans