Thursday, May 24, 2012

DAX 2012 Data Model - Global Address Information

In 2012 address table is obsolete (no longer used) and new tables have been  introduced which follow normalization and avoid storing of redundant data.

So this post basically
       - Describes about new data model
       - X++ job to illustrate how address and contact information can be migrated to AX 2012.

New Data Model

-- X++ Job

 Create CSV File from Dynamics AX 2009 as Customer.csv and place it on Desktop,
           Format :
           [CustAccount, Name, Address, ZipCode, State, County, Email, MobileNo]


static void Demo_CustomerAddrImport(Args _args)
{
    #WinAPI
    CustTable                   custTable;
    DirPartyTable               dirPartyTable;
    LogisticsAddressZipCode     zipCode;
    LogisticsLocation           logisticsLocation;
    DirPartyLocation            partyLocation;
    LogisticsPostalAddress      postalAddress;
    LogisticsElectronicAddress  contactTable;
    DirPartyLocationRole        partyLocationRole;
    LogisticsLocationRole       locationRole = LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice);
    container                   roleId = [locationRole.RecId];
    LogisticsPostalAddressView  postalAddrView;


    CommaIO        commaIO = new CommaIO(strfmt("%1%2", WinAPI::getFolderPath(#CSIDL_DESKTOPDIRECTORY), "\\Customer.csv"), "r");
    Container      record;
    Name           name;


    void createPostalAddr(LogisticsLocationRecId _recId, LogisticsPostalAddressView _postalAddrView)
    {
        LogisticsPostalAddressEntity postalAddrEntity = LogisticsPostalAddressEntity::construct(_recId);
        ;


        postalAddrEntity.createPostalAddress(_postalAddrView);


    }
    ;




    while (commaIO.status() == IO_Status::Ok)
    {
        record = commaIO.read();
        name = conPeek(record, 2);


        custTable = custTable::find(conPeek(record, 1));
        if (custTable)
        {


            // Create postal address
            logisticsLocation.clear();
            logisticsLocation = LogisticsLocation::create("Legacy Postal Address", NoYes::Yes);


            postalAddress.Location = logisticsLocation.RecId;
            postalAddress.Address  = conPeek(record, 3);
            postalAddress.ZipCode  = conPeek(record, 4);
            postalAddress.State    = conPeek(record, 5);
            postalAddress.County   = conPeek(record, 6);
            postalAddress.CountryRegionId = "DNK";
            postalAddress.ValidFrom = DateTimeUtil::newDateTime(01\01\2010, 01);
            postalAddress.insert();


            // Attach to party and sepecify address type like Delivery, Invoice
            partyLocation.clear();
            partyLocation.initValue();
            partyLocation.Party = custTable.Party;
            partyLocation.Location = logisticsLocation.RecId;
            partyLocation.IsPostalAddress = NoYes::Yes;
            partyLocation.insert();




            DirPartyLocationRole::createPartyLocationRoles(partyLocation.RecId, roleId, false);


            if (conPeek(record, 7) != "")
            {
                // Create postal address
                logisticsLocation.clear();
                logisticsLocation = LogisticsLocation::create("Email Contact", NoYes::Yes);


                contactTable.clear();
                contactTable.Location = logisticsLocation.RecId;
                contactTable.Locator  = conPeek(record, 7);
                contactTable.Type     = LogisticsElectronicAddressMethodType::Email;
                contactTable.insert();


                // Attach to party
                partyLocation.clear();
                partyLocation.initValue();
                partyLocation.Party = custTable.Party;
                partyLocation.Location = logisticsLocation.RecId;
                partyLocation.insert();
            }


            if (conPeek(record, 8) != "")
            {
                // Create postal address
                logisticsLocation.clear();
                logisticsLocation = LogisticsLocation::create("Phone Contact", NoYes::Yes);


                contactTable.clear();
                contactTable.Location = logisticsLocation.RecId;
                contactTable.Locator  = conPeek(record, 8);
                contactTable.Type     = LogisticsElectronicAddressMethodType::Phone;
                contactTable.insert();


                // Attach to party
                partyLocation.clear();
                partyLocation.initValue();
                partyLocation.Party = custTable.Party;
                partyLocation.Location = logisticsLocation.RecId;
                partyLocation.insert();
            }
       
        }
    }
}

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...