title: Get all addresses on the system Dynamics AX 2012
body: <p><strong>QUESTION:</strong></p>
  
  <p>I would like to know how can I get all the addresses on the system, including (customers, vendors, banks and tax authorities) on a query, and put it on a view with columns (<em>name</em>, <em>address</em>).
  So it would be parties and non-parties entities.</p>
  
  <p><strong>WHAT I'VE TRIED TO DO:</strong></p>
  
  <p>I use the table concepts to figure out the problem for parties:</p>
  
  <p><img src="https://i.stack.imgur.com/cKr7z.jpg" alt="Part of the LOCATION DATA MODEL"></p>
  
  <p><strong>LogisticsPostalAddress</strong> - table contains addresses in the system that could be associated with various entities.
  Is where the main information about the addresses are, it seems that the rest are extra descriptions of these addresses.</p>
  
  <p>The <strong>CustTable</strong> and VendTable have a FK to <strong>DirPartyTable</strong>.
  The <strong>BankAccountTable</strong> and the <strong>TaxAuthorityAddress</strong> have the relation directly with the <strong>LogisticsLocation</strong> that have relation with the <strong>LogisticsPostalAddress</strong>, at the relation  Location_FK.</p>
  
  <p><strong>The question now is how to build the <em>query</em> that gets the addresses from Customers, BankAccounts, Vendors and Tax Authorities and put it on a view with (name,address) pair?</strong></p>
  
  <p><em>EDITED</em></p>
  
  <p>I have found a way to get all addresses using a method, but not using a query, and is not very efficient, but it was enough for what I wanted:</p>
  
  <p>1) Create a table: <code>AllAddresses</code> for example:
  With fields: <em>Name, Address</em></p>
  
  <p>2) Create a job:</p>
  
  <pre><code>static void GettingAllAddresses(Args _args)
  {
      CustTable custTable;
      VendTable vendTable;
      TaxAuthorityAddress taxAuthorityAddress;
  
      LogisticsPostalAddress logisticsPostalAddress;
      AllAddresses allAddresses;
  
      ;
  
      while select * from custTable
      {
          allAddresses.Address = custTable.address();
          allAddresses.Name = custTable.name();
          allAddresses.CustAccount = custTable.AccountNum;
          allAddresses.doInsert();
      }
  
  
  
      //Getting all vendors
      while select * from vendTable
      {
  
          allAddresses.Address = vendTable.address();
          allAddresses.Name = vendTable.name();
          allAddresses.doInsert();
      }
  
      //Getting all tax authorities addresses
      while select * from taxAuthorityAddress
      {
  
  
          allAddresses.Address = TaxAuthorityAddress::address(taxAuthorityAddress.TaxAuthority);
          allAddresses.Name = taxAuthorityAddress.Name;
          allAddresses.doInsert();
      }
  
      //Getting all bank addresses
      while select * from bankAccountTable
      {
          logisticsPostalAddress = LogisticsLocationEntity::location2PostalAddress(bankAccountTable.Location);
          allAddresses.Address = logisticsPostalAddress.Address;
          allAddresses.Name = bankAccountTable.Name;
          allAddresses.doInsert();
      }
  }
  </code></pre>