Purpose:
The purpose of this blog post is to share handy queries for addresses and contact information with the community
- Get site from contact information record
- Get site from address record
- Get warehouse from contact information record
- Get warehouse from address record
- Get customer from contact information record
- Get customer from address record
- Get vendor from contact information record
- Get vendor from address record
Product:
D365 Finance and Operations + Dynamics AX 2012
Code:
static void Address_Contact_Info_Queries(Args _args)
{
InventLocationLogisticsLocation inventLocationLogisticsLocation;
InventSiteLogisticsLocation inventSiteLogisticsLocation;
LogisticsElectronicAddress logisticsElectronicAddress;
LogisticsPostalAddress logisticsPostalAddress;
LogisticsLocation logisticsLocation;
InventLocation inventLocation;
InventSite inventSite;
DirPartyLocation dirPartyLocation;
DirPartyTable dirPartyTable;
CustTable custTable;
VendTable vendTable;
;
// Get site from communication details
while select inventSite
join inventSiteLogisticsLocation
where inventSiteLogisticsLocation.Site == inventSite.RecId
join firstonly logisticsLocation
where logisticsLocation.ParentLocation == inventSiteLogisticsLocation.Location
join firstOnly logisticsElectronicAddress
where logisticsElectronicAddress.Location == logisticsLocation.RecId
&& logisticsElectronicAddress.RecId == 5637634246
{
info(strFmt("1. Site contact %1 %2",
inventSite.SiteId,
logisticsElectronicAddress.Locator));
}
// Get site from addresses
while select inventSite
join inventSiteLogisticsLocation
where inventSiteLogisticsLocation.Site == inventSite.RecId
join firstonly logisticsLocation
where logisticsLocation.RecId == inventSiteLogisticsLocation.Location
join firstOnly logisticsPostalAddress
where logisticsPostalAddress.Location == logisticsLocation.RecId
&& logisticsPostalAddress.RecId == 5638869576
{
info(strFmt("2. Site address %1 %2",
inventSite.SiteId,
logisticsPostalAddress.Address));
}
// Get warehouse from communication details
while select inventlocation
join inventLocationLogisticsLocation
where inventLocationLogisticsLocation.InventLocation == inventlocation.RecId
join firstonly logisticsLocation
where logisticsLocation.ParentLocation == inventLocationLogisticsLocation.Location
join firstOnly logisticsElectronicAddress
where logisticsElectronicAddress.Location == logisticsLocation.RecId
&& logisticsElectronicAddress.RecId == 5639502490
{
info(strFmt("3. Warehouse contact %1 %2",
inventlocation.InventLocationId,
logisticsElectronicAddress.Locator));
}
// Get warehouse from addresses
while select inventlocation
join inventLocationLogisticsLocation
where inventLocationLogisticsLocation.InventLocation == inventlocation.RecId
join firstonly logisticsLocation
where logisticsLocation.RecId == inventLocationLogisticsLocation.Location
join firstOnly logisticsPostalAddress
where logisticsPostalAddress.Location == logisticsLocation.RecId
&& logisticsPostalAddress.RecId == 5638869577
{
info(strFmt("4. Warehouse address %1 %2",
inventlocation.InventLocationId,
logisticsPostalAddress.Address));
}
// Get customer from communication details
while select custTable
join dirPartyTable
where dirPartyTable.RecId == custTable.Party
join dirPartyLocation
where dirPartyLocation.Party == dirPartyTable.RecId
join firstOnly logisticsLocation
where logisticsLocation.RecId == dirPartyLocation.Location
join firstOnly logisticsElectronicAddress
where logisticsElectronicAddress.Location == logisticsLocation.RecId
&& logisticsElectronicAddress.RecId == 5638681887
{
info(strFmt("5. Customer contact %1 %2",
custTable.AccountNum,
logisticsElectronicAddress.Locator));
}
// Get customer from addresses
while select custTable
join dirPartyTable
where dirPartyTable.RecId == custTable.Party
join dirPartyLocation
where dirPartyLocation.Party == dirPartyTable.RecId
join firstOnly logisticsLocation
where logisticsLocation.RecId == dirPartyLocation.Location
join firstOnly logisticsPostalAddress
where logisticsPostalAddress.Location == logisticsLocation.RecId
&& logisticsPostalAddress.RecId == 5638869578
{
info(strFmt("6. Customer address %1 %2",
custTable.AccountNum,
logisticsPostalAddress.Address));
}
// Get vendor from communication details
while select vendTable
join dirPartyTable
where dirPartyTable.RecId == vendTable.Party
join dirPartyLocation
where dirPartyLocation.Party == dirPartyTable.RecId
join firstOnly logisticsLocation
where logisticsLocation.RecId == dirPartyLocation.Location
join firstOnly logisticsElectronicAddress
where logisticsElectronicAddress.Location == logisticsLocation.RecId
&& logisticsElectronicAddress.RecId == 5638265744
{
info(strFmt("7. Vendor contact %1 %2",
vendTable.AccountNum,
logisticsElectronicAddress.Locator));
}
// Get vendor from addresses
while select vendTable
join dirPartyTable
where dirPartyTable.RecId == vendTable.Party
join dirPartyLocation
where dirPartyLocation.Party == dirPartyTable.RecId
join firstOnly logisticsLocation
where logisticsLocation.RecId == dirPartyLocation.Location
join firstOnly logisticsPostalAddress
where logisticsPostalAddress.Location == logisticsLocation.RecId
&& logisticsPostalAddress.RecId == 5638869579
{
info(strFmt("8. Vendor address %1 %2",
vendTable.AccountNum,
logisticsPostalAddress.Address));
}
}