This post shows the code which helps in retrieving the address of Party (Customer, Vendor etc.) by providing the type of addresses.
Function which takes Party and LogisticsLocationRoleType (Invoice, Delivery, Shipping etc.)
public static LogisticsPostalAddress getPostalAddressByType(DirPartyRecId _party, LogisticsLocationRoleType _type)
{
DirPartyLocation partyLocation;
DirPartyLocationRole partyLocationRole;
LogisticsLocation location;
LogisticsLocationRole locationRole;
LogisticsPostalAddress postalAddress;
select firstonly postalAddress
exists join location
where location.RecId == postalAddress.Location
exists join locationRole
where locationRole.Type == _type
exists join partyLocation
where
partyLocation.Location == location.RecId &&
partyLocation.Party == _party
exists join partyLocationRole
where partyLocationRole.PartyLocation == partyLocation.RecId &&
partyLocationRole.LocationRole == locationRole.RecId;
return postalAddress;
}
Function which takes Party and LogisticsLocationRoleType (Invoice, Delivery, Shipping etc.)
public static LogisticsPostalAddress getPostalAddressByType(DirPartyRecId _party, LogisticsLocationRoleType _type)
{
DirPartyLocation partyLocation;
DirPartyLocationRole partyLocationRole;
LogisticsLocation location;
LogisticsLocationRole locationRole;
LogisticsPostalAddress postalAddress;
select firstonly postalAddress
exists join location
where location.RecId == postalAddress.Location
exists join locationRole
where locationRole.Type == _type
exists join partyLocation
where
partyLocation.Location == location.RecId &&
partyLocation.Party == _party
exists join partyLocationRole
where partyLocationRole.PartyLocation == partyLocation.RecId &&
partyLocationRole.LocationRole == locationRole.RecId;
return postalAddress;
}
Demonstration:
Consider a customer having following addresses defined.
Code
static void BlogTestJob(Args _args)
{
CustTable custTable;
custTable = CustTable::find('2202');
info(strFmt('Delivery Address: %1', getPostalAddressByType(custTable.Party, LogisticsLocationRoleType::Delivery).Address));
info(strFmt('Invoice Address: %1', getPostalAddressByType(custTable.Party, LogisticsLocationRoleType::Invoice).Address));
}
Thank you so much. Exactly what I needed and very well presented too.
ReplyDelete