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 :
Microsoft Dynamics AX (Archived)

Hanging when trying to delete records

(0) ShareShare
ReportReport
Posted on by 135
ttsBegin;
    //Delete all added addresses resulting from merge
    if (aHACustMerge.changePrimary || aHACustMerge.changeAddress)
    {
        /*while select survivorDirPartyLocation
            where survivorDirPartyLocation.Party == survivor.Party
            join survivorLogisticsPostalAddress
            where survivorLogisticsPostalAddress.Location == survivorDirPartyLocation.Location
                && survivorLogisticsPostalAddress.HAMergeVictim == victim.AccountNum
        {
            survivorLogisticsPostalAddress.delete();
        }*/

        while select survivorDirPartyLocation
            where survivorDirPartyLocation.Party == survivor.Party
            join survivorLogisticsLocation
            where survivorLogisticsLocation.recid == survivorDirPartyLocation.location
                && survivorLogisticsLocation.HAMergeVictim == victim.accountNum
        {
            survivorLogisticsLocation.selectForUpdate(true);
            survivorLogisticsLocation.delete();
        }
    }
    ttsCommit;

For some reason the code above just seems to hang and never finish.  At first, I thought the two queries were conflicting with each other and causing deadlock, so I commented out the first one, but it's still hanging.  First time deleting records, so maybe I did something wrong.  Please let me know.  Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    BrandonSA Profile Picture
    1,673 on at

    Hi AXGreenHorn

    I'm not sure what the prob is, but here are a few pointers to improve the code altogether:

    - When calling delete in a while like that, instead of using selectForUpdate(true), rather perform the select like this:

    while select forupdate survivorDirPartyLocation

    - Secondly, you can scrap the while loop altogether. Rather use a delete_from like this: (https://docs.microsoft.com/en-us/dynamicsax-2012/developer/delete-from). You don't perform this operation inside a tts transaction

    delete_from survivorDirPartyLocation
                where survivorDirPartyLocation.Party == survivor.Party
                join survivorLogisticsLocation
                where survivorLogisticsLocation.recid == survivorDirPartyLocation.location
                    && survivorLogisticsLocation.HAMergeVictim == victim.accountNum;

    - Also, do you have code on the delete methods of those tables?

    - I'm also assuming the survivor and victim record buffers have values...

    - How many records are you trying to delete?

    Hope this helps

  • Suggested answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    Table you are trying to delete must have  lot of data  , so it make sense to use delete_ from statement instead of while select . why you want to delete  LogisticsLocation table though ?

  • AXGreenHorn Profile Picture
    135 on at
    delete_from survivorDirPartyLocation
                where survivorDirPartyLocation.Party == survivor.Party
                join survivorLogisticsLocation
                where survivorLogisticsLocation.recid == survivorDirPartyLocation.location
                    && survivorLogisticsLocation.HAMergeVictim == victim.accountNum;

    I changed the code to this, but when I try to compile I get the error, "Inner or outer join is illegal in this context" with the "join survivorLogisticsLocation" underlined in red.  However, I think that this is the right approach and I'm just missing something.

  • AXGreenHorn Profile Picture
    135 on at

    I need to delete some addresses from an account.  My understanding is that deleting the relevant logisticslocation records will cascade delete the appropriate addresses.

  • Verified answer
    AXGreenHorn Profile Picture
    135 on at

    So the problem is that deleting addresses is an extremely expensive operation due to all the validation checking required.  It's better just to expire the addresses instead.  Would have been nice if this was stated on the MS documentation.

    How do I close this question now that I've figured it out?

  • André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at

    Hi AXGreenHorn,

    You can click on the 'Yes' link below 'Did this answer your question?'. Mark only the answer(s) that has the correct information for your resolution. So at least, mark your own reply.

  • AXGreenHorn Profile Picture
    135 on at

    There is no "Yes" under the "Did this answer your question?"

    01406.Capture.PNG

  • André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at

    Sorted with my moderator privileges.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans