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
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."); }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156