Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Removing Duplicate Address

(1) ShareShare
ReportReport
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

*This post is locked for comments

  • 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;
    }

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans