Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Removing Duplicate Address

Posted on by Microsoft Employee

Hello Experts,

In Dynamic Ax 2012 I have lots of duplicate address in the table LogisticsPosatalAddress i want to remove that duplication and update all the references. I have made the View which show me the Duplicate address with count.  Can Anybody help how to delete the duplication and update the corresponding references 

8_2D00_28_2D00_2017-7_2D00_22_2D00_44-PM.png

Categories:
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Removing Duplicate Address

    Hi Chaitanya,

    Thanks for the help sure i will test on my system and check. If the system handles the that references automatically its good as i want only primary address

    Thanking You,

    Krutish Ruparelia

  • Verified answer
    Chaitanya Golla Profile Picture
    Chaitanya Golla 17,225 on at
    RE: Removing Duplicate Address

    Hi,

    I feel update of references will be taken care by system itself.The code I provided is taken from method main of Class DirPartyPostalAddressAction which is the one that is called when we try to delete the address from CustTable/VendTable form. I tried for regular & primary address and it worked as expected. Anyway please check on test system once before actual deletion.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Removing Duplicate Address

    Thanks Chaitanya for suggesting me this option but i have 1 more query,

    See i have duplicate address in LogisticsPostalAddress Table if i delete the any of the address from that table do i need to update the references of all the field which are connected to this because this table is refereed with more the other 20 tables with the foreign key constraint

  • Verified answer
    Chaitanya Golla Profile Picture
    Chaitanya Golla 17,225 on at
    RE: Removing Duplicate Address

    Hi,

    Following code can be used to delete a specific address(identified by a location name) for a given customer.

    Iterate with your view, considering records with the duplicate count greater than 2. Please test it on your test system once.

    static void AddressDeletion(Args _args)
    {
        LogisticsLocation   location;
        DirPartyLocation    dirPartyLocation, partyLocation;
        DirPartyLocation    dirPartyLocationSecondary;
        CustTable           custTable;
        boolean             confirmDelete = true;
    
        ttsBegin;
        select firstonly custTable
            join partyLocation
            where partyLocation.Party == custTable.Party
            join forUpdate location
            where location.RecId == partyLocation.location;
            //&& location.Description == "XYZ"; 
    
        select firstonly RecId, Location, Party from dirPartyLocationSecondary
        where dirPartyLocationSecondary.Location == partyLocation.Location && dirPartyLocationSecondary.Party != partyLocation.Party;
    
        if(dirPartyLocationSecondary.RecId != 0)
        {
            select dirPartyLocation
            where dirPartyLocation.RecId == partyLocation.RecId;
    
            if (dirPartyLocation.RecId != 0)
            {
                // Show dialog to update parties that share this address
                confirmDelete = LogisticsEntityLocationMap::showSharedAddressDialog(dirPartyLocation);
            }
        }
    
        if (confirmDelete && dirPartyLocation.RecId != 0 && location.validateDelete())
        {
            location.delete();
        }
        else if (dirPartyLocation.RecId == 0 && location.validateDelete())
        {
            location.delete();
        }
        ttsCommit;
    }

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

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…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans