Thursday, 29 September 2011

Basic Address Book structure in Ax2012

This is a quick overview of the main tables involved in the address book functionality of Ax2012.

In Ax2009, the integration between the address book and 'entities', like customers, suppliers, etc was a bit flaky. This has been tightened up in Ax2012 so that now the address book has a much more important role in maintaining basic data like customer names and addresses etc.

A few of the tables you'll need to know about are:


Table Description
DirPartyTable Global address book. This will contain entries for all people and organizations
you deal with, including customers, suppliers, employees, etc.


This information is maintained across the entire organization. NB the table structure often refers to address book entries as 'parties'. Generally other records (like customer, supplier, etc) will reference a record in this table by a field named Party.
LogisticsLocation This is a single 'location' that can be attached to one or more address book entries. This is similar in principle to the old 'Address' table from Ax2009, that no longer exists - The main difference now being that the location header always points to an address book entry, whereas in 2009 the Address table could point to anything.

Note that this is not an address - Physical address details are stored in
LogisticsPostalAddress
LogisticsPostalAddress A postal address, linked to a LogisticsLocation record via field Location.
LogisticsElectronicAddress 'Electronic' address details, such as email, phone, web address etc.

Each different type of address is represented as a separate record, delineated by 'Type'. This links to the location record.
DirPartyLocation This table links entries in the LogisticsLocation table to an address book entry (DirPartyTable).
LogisticsLocationRole This defines types of roles that an address are classified as, such as "Delivery", "Invoice", etc.
DirPartyLocationRole Links a location role type (LogisticsLocationRole) and an address book entry (DirPartyTable)
DirPartyPostalAddressView (view) This is a view that collates address book entries with their linked postal addresses

A few of the address book tables you should know about


The following code sample shows how we could obtain the postal addresses for a customer. NB You would preferably use a view or joined queries to get this information. I've expanded it out to demonstrate the relationships.


static void ShowCustomerAddressBookDetails(Args _args)
{
    CustTable               custTable;
    DirPartyTable           dirPartyTable;
    DirPartyLocation        partyLocation;
    LogisticsLocation       logisticsLocation;
    LogisticsPostalAddress  postalAddress;
    ;
    custTable       = custTable::find('2014');
    dirPartyTable   = dirPartyTable::findRec(custTable.Party);
    while select partyLocation
        where   partyLocation.Party     == dirPartyTable.RecId
    {
        logisticsLocation = logisticsLocation::find(partyLocation.Location);        
        if(logisticsLocation.IsPostalAddress)
        {
            postalAddress = LogisticsPostalAddress::findByLocation(logisticsLocation.RecId);            
            info(strFmt("%1 - %2",
                logisticsLocation.Description,
                postalAddress.CountryRegionId));
        }        
    }
}
Obtaining postal addresses from a customer

And to get the email addresses:

static void ShowCustomerEmailAddresses(Args _args)
{
    CustTable                   custTable;
    DirPartyTable               dirPartyTable;
    DirPartyLocation            partyLocation;
    LogisticsLocation           logisticsLocation;
    LogisticsElectronicAddress  electronicAddress;
    ;
    custTable       = custTable::find('2014');
    dirPartyTable   = dirPartyTable::findRec(custTable.Party);
    while select partyLocation
        where   partyLocation.Party     == dirPartyTable.RecId
    {
        logisticsLocation = logisticsLocation::find(partyLocation.Location);        
        while select electronicAddress
            where   electronicAddress.Location  == logisticsLocation.RecId
            &&      electronicAddress.Type      == LogisticsElectronicAddressMethodType::Email
        {            
            info(strFmt("%1",electronicAddress.Locator));
        }        
    }
}

Obtain customer email addresses


The following code sample retrieves the phone numbers attached to a warehouse. It was added in response to a question from adiso.

static void FindPhoneNumbersAttachedToWarehouse(Args _args)
{

    InventLocation                      inventLocation;
    LogisticsEntityPostalAddressView    postalAddressView;
    LogisticsElectronicAddress          elecAddress;
    LogisticsLocation                   contactLocation;
    
    inventLocation = inventLocation::find('11');
    
    if(inventLocation)
    {
        while select postalAddressView  
            where   postalAddressView.Entity            == inventLocation.RecId
            &&      postalAddressView.EntityType        == LogisticsLocationEntityType::Warehouse
        {                
            while select elecAddress                
                where   elecAddress.Type                == LogisticsElectronicAddressMethodType::Phone
            join contactLocation                                    
                where   contactLocation.ParentLocation  == postalAddressView.Location
                &&      contactLocation.RecId           == elecAddress.Location
            {            
                info(elecAddress.Locator);   
            }                   
        }
    }

}

5 comments:

  1. Hi,
    Can you post a sample how to get the phone number
    for an InventLocation Record ?
    I'm missing the part with dirPartyTable.
    I checked the pdf Implementing the address
    book framework for Microsoft Dynamics AX 2012
    applications and nothing!
    I got stuck


    static void ShowPlantPhone(Args _args)
    {
    InventLocation InventLocation;
    DirPartyTable dirPartyTable;
    DirPartyLocation partyLocation;
    LogisticsLocation logisticsLocation;
    LogisticsElectronicAddress electronicAddress;
    ;
    InventLocation = InventLocation::find('02');
    logisticsLocation = LogisticsLocation::find(InventLocation.RecId);



    while select electronicAddress
    where electronicAddress.Location == logisticsLocation.RecId
    && electronicAddress.Type == LogisticsElectronicAddressMethodType::Phone
    {
    info(strFmt("%1",electronicAddress.Locator));
    }

    }

    ReplyDelete
    Replies
    1. Hi - I've added a code sample showing how to get phone numbers for a warehouse.

      Delete
  2. Thanks..You are the best !
    I found a solution by myself after I had to do some digging
    I did this one as a method to InventLocation

    and I call it as
    phone= InventLocation::find('02').phone();



    Phone phone()
    {
    LogisticsElectronicAddress electronicAddress ;
    LogisticsLocation LogisticsLocation;
    RecId LogisticsLocationRecid,ParentRecid;

    LogisticsLocationRecid=this.DeliveryAddress().Location;

    select firstOnly LogisticsLocation where LogisticsLocation.ParentLocation == LogisticsLocationRecid;

    return LogisticsElectronicAddress::findByLocationandType(LogisticsLocation.RecId,LogisticsElectronicAddressMethodType::Phone).Locator;





    }

    ReplyDelete
  3. Thanks, just made my life easier in understanding an overview of the the address book framework AX 2012 R2

    ReplyDelete
  4. Thanks so much for laying this out very simply.

    ReplyDelete