Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / use "delete from" to d...
Finance forum
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

use "delete from" to delete records

Posted on by 254
Hi, 

Can i get rid of the while loop in the code below and make the delete faster?

I have an order header table (table1),  where this order has 2 types of lines (tableline1 and tableline2)
so it's like salesTable and imagine there is salesLine1 table and SalesLine2 table both linked to header salesTable

and i want to delete all orders with their 2 table lines where the header has a specifIc value for InventLocationId
and of course i need to make sure i delete the lines tables first before the header
class DeleteOrderService extends SysOperationServiceBase
{

    public void deleteOrder()
    {
        Table1              table1;
        TableLine1          line1Delete;
        TableLine2          line2Delete;
        Table1              table1Delete;


        while select Id from table1 where table1.InventLocationId == XParameters::find().LocationId
        {
            delete_from line1Delete where line1Delete.Id == table1.Id;
            delete_from line2Delete where line2Delete.Id == table1.Id;
            delete_from table1Delete  where table1Delete.Id == table1.Id;
        }

    }

}

it's like i would like to delete everything that this query returns:
select TABLE1.ID,INVENTLOCATIONID,*from TABLE1
join TABLELINE1 on TABLELINE1.ID = TABLE1.ID
join TABLELINE2 on TABLELINE2.ID = TABLE1.ID
where INVENTLOCATIONID = 'XX'
 

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,451 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,353 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans