Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

find customer primary address

(0) ShareShare
ReportReport
Posted on by 780

How do i find a customer's primary address? I tried it two different ways. The code didn't even compile both ways, so I commented the lines.

static void Jobxx_findprimaryAddress(Args _args)
{

    CustTable custTable;
    DirPartyTable dirPartyTable;
    DirPartyAddress dirPartyAddress;

    ;

    custTable = CustTable::find("ABCD", false);

//first way
    //dirPartyAddress = dirPartyAddress::findPrimaryAddress(custTable.PartyId);

// second way    
    dirPartyTable = DirPartyTable::find(custTable.PartyId);
    //dirPartyAddress = dirPartyAddress::findPrimaryAddress(dirPartyTable.PartyId);
   
    info(strFmt("Street: %1", dirPartyAddress.parmStreet());

}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: find customer primary address

    Mr. Andrew W Ford has submitted the best way of getting primary address here. Mr. Fords suggestion by far out performs the DirPartyAddress::findPrimaryAddress method.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: find customer primary address

    This job works in DAX 2009:

    static void FindPrimaryAddress(Args _args)
    {
        utcDateTime                         dateTimeNow = DateTimeUtil::utcNow();
        CustTable                           custTable;
        DirPartyAddressRelationship         dpar;
        DirPartyAddressRelationshipMapping  dparm;
        Address                             address;
        ;

        select firstfast firstonly custTable;

        
        select firstfast firstonly dpar
            where   dpar.PartyId            == custTable.PartyId
                &&  dpar.Status             == DirPartyAddressRelationshipStatus::Active
                &&  dpar.ValidFromDateTime  <= dateTimeNow
                &&  dpar.ValidToDateTime    >= dateTimeNow
                &&  dpar.IsPrimary          == NoYes::Yes;
               
        select firstfast firstonly dparm
            where   dparm.PartyAddressRelationshipRecId == dpar.RecId;
           
        select firstfast firstonly address
            where   address.RecId   == dparm.AddressRecId;
           
        info(strFmt('Primary address for %1 is %2', custTable.Name, address.Address));
    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: find customer primary address

    try this...

    static void FindPrimaryAddress(Args _args)
    {
        CustTable       custTable;
        Address         primaryAddress;
        ;

        custTable = CustTable::find("ABCD", false);

        //first way
        primaryAddress = dirPartyAddress::findPrimaryAddress(custTable.PartyId);
      
        info(strFmt("Street: %1", primaryAddress.Street));
    }

    your only problem was that findPrimaryAddress returns Address, not DirPartyAddress

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans