web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
Posted on by 3,029

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

I have the same question (0)
  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans