Wednesday, October 16, 2019

Get Customer Address By Type In D365/AX X++

Below is the piece of code to get customer address by type in AX/D365 X++


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

1 comment:

  1. Thanks for sharing this helpful code snippet! Getting customer addresses by type in D365 is often tricky, but this method simplifies it nicely. For anyone working with controllers on Windows, don’t forget to check out the betterjoy download tool it’s great for seamless Nintendo Switch controller support. Keep the great content coming!

    ReplyDelete

What is the primary purpose of using a Solution in Microsoft Power Platform & ALM?

As organizations embrace low-code development with Microsoft Power Platform , it becomes essential to manage and govern apps, flows, and dat...