Tuesday, September 22, 2015

Restoring missing DirPartyLocation info

I came into issue on one of the environment where somehow records of Vendor Contacts data was deleted from DirPartyLocation table and we need to restore the data without backup database as the backup database was way old to recover.

By looking into GAB framework which was introduced in AX 2012, I come to know that DirPartyTable  maintains Primary contacts and address information in the following fields.

  • PrimaryAddressLocation
  • PrimaryContactEmail
  • PrimaryContactFax
  • PrimaryContactPhone
  • PrimaryContactTelex
  • PrimaryContactURL


Since we know that every address or contact is linked to one LocationId in GAB framework, I was able to find LocationId's in LogisticsElectronicAddress against any primary contact info in DirPartyTable.

Contacts Recovery Job:

static void srclVendPrimContactRestoreJob(Args _args)
{
    VendTable               vendTable;
    DirPartyTable           dirPartyTable;
    DirPartyLocation        dirPartyLocation;
    DirPartyContactInfoView dirContactInfoView;

    while select vendTable
        join dirPartyTable
    where dirPartyTable.RecId == vendTable.Party
    {
        if (dirPartyTable.PrimaryContactEmail && (!DirPartyLocation::findByPartyLocation(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactEmail).Location)))
        {
            ttsBegin;
            DirPartyLocation::create(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactEmail).Location, false, true);
            ttsCommit;
        }
        if (dirPartyTable.PrimaryContactFax && (!DirPartyLocation::findByPartyLocation(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactFax).Location)))
        {
            ttsBegin;
            DirPartyLocation::create(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactFax).Location, false, true);
            ttsCommit;
        }
        if (dirPartyTable.PrimaryContactPhone && (!DirPartyLocation::findByPartyLocation(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactPhone).Location)))
        {
            ttsBegin;
            DirPartyLocation::create(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactPhone).Location, false, true);
            ttsCommit;
        }
        if (dirPartyTable.PrimaryContactTelex && (!DirPartyLocation::findByPartyLocation(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactTelex).Location)))
        {
            ttsBegin;
            DirPartyLocation::create(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactTelex).Location, false, true);
            ttsCommit;
        }
        if (dirPartyTable.PrimaryContactURL && (!DirPartyLocation::findByPartyLocation(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactURL).Location)))
        {
            ttsBegin;
            DirPartyLocation::create(vendTable.Party, LogisticsElectronicAddress::findRecId(dirPartyTable.PrimaryContactURL).Location, false, true);
            ttsCommit;
        }
    }
}

No comments:

Post a Comment