Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

AX 2012 R3. Error when trying to set a customer's primary address

Posted on by 2,983

I get this error when trying to set a customer's primary address:

(DirOrganization). The record was never selected.

Debugging, I find that the error is thrown by standard AX 2012 code:

public static void updatePrimaryAddressLocation(DirPartyRecId _party, LogisticsLocationRecId _location)
{
    DirPartyTable partyRecord;

    ttsbegin;
    select forupdate partyRecord where partyRecord.RecId == _party;

    if (partyRecord.PrimaryAddressLocation != _location)
    {
        partyRecord.PrimaryAddressLocation = _location;
        partyRecord.doUpdate(); // ==> THIS LINE THROWS THE ERROR, altough the record exists in DirPartyTable
    }
    ttscommit;
}

This is the call stack:

[s] \Data Dictionary\Maps\LogisticsEntityLocationMap\Methods\updatePrimaryLocation 48
[s] \Data Dictionary\Tables\DirPartyLocation\Methods\updatePrimaryLocation 3
[s] \Data Dictionary\Tables\DirPartyLocation\Methods\Update 6
[s] \Classes\xRecord\write
[s] \Data Dictionary\Maps\LogisticsEntityLocationMap\Methods\addEntityLocation 39
[s] \Data Dictionary\Tables\DirPartyLocation\Methods\addEntityLocation 4
[c] \Classes\LogisticsEntityLocationFormHandler\write 28
[c] \Classes\LogisticsEntityPostalAddressFormHandler\write 13
[c] \Classes\DirPartyPostalAddressFormHandler\write 5
[c] \Forms\LogisticsPostalAddress\Data Sources\LogisticsPostalAddress\Methods\written 10
[c] \Classes\FormDataSource\leaveRecord

*This post is locked for comments

  • Suggested answer
    Chaitanya Golla Profile Picture
    Chaitanya Golla 17,225 on at
    RE: AX 2012 R3. Error when trying to set a customer's primary address

    Hi,

    Instead you can use below code to set customer primary address.

    Source: www.hodgsontech.com/.../update-customer-primary-address-dynamics-ax

    static void updateCustomerAddress(Args _args) 
    { 
       container roles;  
       DirParty dirParty; 
       DirPartyPostalAddressView addressView; 
       LogisticsPostalAddress address; 
       CustTable custtable; 
       DirPartyLocation partyLocation; 
     
    ttsBegin; 
       
       custtable = Custtable::find("C009999");
       address = DirParty::primaryPostalAddress(CustTable.Party); 
       address = DirParty::findPostalAddressByRole(CustTable.Party, LogisticsLocationRoleType::Business); 
       address.ZipCode = "99999"; 
       addressView.IsPrimary = NoYes::Yes;
       addressView.Party = CustTable.Party; 
       addressview.initFromPostalAddress(address); 
       DirParty = DirParty::constructFromPartyRecId(CustTable.Party); 
       roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Business).RecId];
       DirParty.createOrUpdatePostalAddress(addressView,roles);
    
    ttsCommit; 
    
    info("Job Completed."); 
    }


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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans