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.