Bojensen Blogs

Getting addresses by type X++ | Microsoft Dynamics AX & CRM | AXPulse

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; }


Consider a customer having following addresses defined.



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)); }



Getting addresses by type X++ | Microsoft Dynamics AX & CRM | AXPulse

Comments are closed.