Addresses in AX 2012 can get very tricky to understand. Here is my understanding of the framework after some research and SQL analysis.
Here is a list of tables/views that make up the framework
- LogisticsPostalAddress (Address): This table stores the actual physical postal address.
- Postal Address have 2 important fields ValidFrom, ValidTo. This means that there could be multiple
- LogisticsElectronicAddress (Contact): This table stores all the contacts. Contacts are of 2 types
- Contacts linked directly to Customer/Vendor
- Contacts linked to a Postal Address
- LogisticsLocation (Location): This is the link between an Address or a Contact with Party (Customer/Vendor). This brings us to a first interesting observations
- Contacts are not linked directly to Addresses. Rather they are very indirectly linked to Address through a shared Location.
- When we are trying to link a contact directly with a Party, then the structure will be
- Location
- Bunch of Contacts which point to this Location
- When we are trying to link an address with contacts to a Party, then the structure will be
- Location (A)
- Only one Addresses linked to this location.
- Another location (B) with ParentLocation set to above Location A
- Bunch of Contacts linked to the location B.
- We repeat this for each address.
- There is one exception, A location could have multiple addresses linked to it when we use the ValidFrom and ValidTo fields. Essentially there will only be ONE ACTIVE Address at anytime linked to the Location.
- DirPartyPostalAddressView (Party addresses): This view gives us a list of all addresses that are linked to a Party. In customer and Vendor forms this view is used to build the list of addresses
- LogisticsLocationAddressView (??): Explored it a bit is I think a part of the sub query for the above view. Essentially this has a field Location that is linked to RecId of Location table.
- DirPartyTable (Party): Customer/Vendors
- DirPartyLocation (Party Location): This is linked to Party table and Location table through its 2 fields Party and Location. (They are both FK to RecIds on those tables)
I had to figure out a list of all contacts that are linked to a party addresses. (Basically for each address linked to a party, find out the contacts and show them all together). The following SQL query will solve that problem and hopefully you can figure out the equivalent X++ syntax.
Select * From MicrosoftDynamicsAX.dbo.LOGISTICSELECTRONICADDRESS Where Location In
(Select RECID From MicrosoftDynamicsAX.dbo.LOGISTICSLOCATION Where PARENTLOCATION In
(Select LOCATION From MicrosoftDynamicsAX.dbo.DIRPARTYPOSTALADDRESSVIEW Where PARTY In (Select PARTY From MicrosoftDynamicsAX.dbo.CUSTTABLE Where ACCOUNTNUM = ’902310′)))
That sums up my research so far.