Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Customer address through code in AX 2012 r3

(0) ShareShare
ReportReport
Posted on by 18

hi

2627.A2.jpg

i wrote below code to display address of customer, BUT it's not printing the "Japan"

while select AccountNum,party from custTable where custTable.AccountNum == customerCode
    {
        if(custTable)
        {
            party       = custTable.Party;
            description = DirParty::primaryPostalAddress(party).displayLocationDescription();
            address     = DirParty::getPostalAddressByType(party, LogisticsLocationRoleType::Delivery);

            // phone -- customer
            logisticsElectronicAddress = DirParty::primaryElectronicAddress(party, LogisticsElectronicAddressMethodType::Phone);
            if(logisticsElectronicAddress)
            {
                locator = logisticsElectronicAddress.Locator;
            }

            // fax -- customer
            logisticsElectronicAddress2 = DirParty::primaryElectronicAddress(party, LogisticsElectronicAddressMethodType::Fax);
            if(logisticsElectronicAddress2)
            {
                locator2 = logisticsElectronicAddress2.Locator;
            }

        }
    }

Output

6076.report2.jpg

Please give me more shed on this.

thanks!

  • WillWU Profile Picture
    22,352 on at
    RE: Customer address through code in AX 2012 r3

    Hi @rp@n,

    Where is your code to output the address? I can't find it.

    This line will return the Delivery address of your customer. DirParty::getPostalAddressByType(party, LogisticsLocationRoleType::Delivery)

    Have you used a placeholder somewhere? I suggest you print out the address directly and check it.

    Hope this helps.

  • Suggested answer
    Sukrut Parab Profile Picture
    71,682 Moderator on at
    RE: Customer address through code in AX 2012 r3

    If you debug and see you are getting full value in your address variable its a problem  where you are printing it. How /Where do you printing your output ?

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Customer address through code in AX 2012 r3

    Arpan,

    Were you able to resolve this issue?

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Customer address through code in AX 2012 r3

    There is nothing wrong with this call. You may want to check the data in LogisticsPostalAddress Table.

    An alternative could be to write your own method -

    public static Addressing 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//LogisticsLocationRoleType::Invoice
            exists join partyLocation
                where 
                    partyLocation.Location      == location.RecId &&
                    partyLocation.IsPrimary     == NoYes::Yes && 
                    partyLocation.Party         == _party
            exists join partyLocationRole
                where partyLocationRole.PartyLocation   == partyLocation.RecId &&
                    partyLocationRole.LocationRole      == locationRole.RecId;
    
        return postalAddress.Address;
    }

    Also, it looks like you are trying to get the Delivery address for a sales order. Can you not use the SalesTable\deliveryAddress method?

  • @rp@n Profile Picture
    18 on at
    RE: Customer address through code in AX 2012 r3

    select salesInvoiceHeaderFooterTmp;
    salesInvoiceHeaderFooterTmp.Address         = address;
    
    salesInvoiceHeaderFooterTmp.insert();

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Customer address through code in AX 2012 r3

    Hi Arpan,

    It is not sure from your code which field you are choosing to display address.

    Can you share the entire code that you are using?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,011 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans