28 Jul. 2011

Import customer address in the Global Address Book

In AX 2012 the GAB (Global Address Book) has gone through some serious changes and now the address information for the customers and vendors is kept in the LogisticsPostalAddress,and LogisticsPostalAddressExt tables. Additional information is maintained in the LogisticsAddress* tables.

This is the simplest possible example of how to create new customer and populate the customer's address information in AX 2012. Note that you may have to modify this code in order to handle the creation of records in the LogisticsAddress* tables.

        CustTable                       custTable;
        AccountNum                      accountNum = 'ABC-123';
        CustGroupId                     custGroupId = '10';
        Name                            name = 'ABC';
        
        DirParty                        dirParty;
        DirPartyPostalAddressView       dirPartyPostalAddressView;


        ttsBegin;

        custTable.clear();
        custTable.initValue();

        custTable.AccountNum = accountNum;
        custTable.CustGroup = custGroupId;

        custTable.insert(DirPartyType::Organization, name);

        dirParty = DirParty::constructFromCommon(custTable);

        dirPartyPostalAddressView.LocationName = 'ABC-AUTO';
        dirPartyPostalAddressView.City = 'London';
        dirPartyPostalAddressView.Street = 'Dover Street';
        dirPartyPostalAddressView.StreetNumber = '123';
        dirPartyPostalAddressView.CountryRegionId = 'GBR';

        dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);

        ttsCommit;

7 comments:

  1. Very good! Thanks for sharing!

    ReplyDelete
  2. Excellent article on inserting address to entities

    ReplyDelete
  3. Thanks! Exactly what i am looking for.

    ReplyDelete
  4. Hi,
    I have used above code to assign address for the specific customer. When I need to update the address for that customer, the createorupdatePostalAddress method is creating new line for address always.

    Please can you suggest how to update the address which is already assigned to that customer.

    Thanks...

    ReplyDelete
    Replies
    1. Ambanna,

      Have you tried something like this:


      CustTable custTable = CustTable::find(""); // your customer here
      DirPartyLocation dirPartyLocation;
      DirPartyPostalAddressView dirPartyPostalAddressView;

      dirParty = DirParty::constructFromCommon(custTable);

      while select dirPartyLocation
      where dirPartyLocation.Party == custTable.Party
      join dirPartyPostalAddressView
      where dirPartyPostalAddressView.Location == dirPartyLocation.Location
      && dirPartyPostalAddressView.Party == dirPartyLocation.Party
      {
      dirPartyPostalAddressView.Street = "New street name here";
      dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
      }

      Please note that handling the old records in the logisticsPostalAddress* tables is a different matter
      and you can deal with it according to your specific circumnstances.

      Delete
  5. Hi,
    when trying to edit Address I am getting following error:
    Cannot Update record in dirPartyPostalAddressView. Microsoft Dynamics AX Views are read only.
    Do you have any idea about this?

    ReplyDelete
  6. Can u please tell me how can i update the contact information...

    ReplyDelete