To Find or Update the customer primary Address in Ax, can try following code. Relation between Dirpartytable and CustTable slightly changed in Ax for you need to re-learn about this.
static void Jay_updateaddress (Args _args) {
container roles;
DirParty DirParty;
Dirpartypostaladdressview Addressview;
Logisticspostaladdress address;
CustTable CustTable;
Dirpartylocation partylocation;
;
Ttsbegin;
CustTable = Custtable::find ("Cust-000025");
Address = DirParty::p rimarypostaladdress (Custtable.party); Find primary Address
/* Locate the first address and update the first address to the primary address
Select Firstonly Address Join Forupdate partylocation
where partylocation.location = = address. Location
&& Partylocation.party = = Custtable.party;
Partylocation.isprimary = Noyes::yes;
Partylocation.update ();
*/
Address. City = "Cangzhou";
Address. State = "Hebei province";
Addressview.party = Custtable.party;
Addressview.initfrompostaladdress (address);
DirParty = Dirparty::constructfrompartyrecid (Custtable.party);
roles = [Logisticslocationrole::findbytype (logisticslocationroletype::business). RECID]; Address Type
Dirparty.createorupdatepostaladdress (Addressview,roles);
Ttscommit;
Info ("Xixi");
}
Note:createorupdatepostaladdress method is useful for both creating or updating the customer address. If you were providing the existing Dirpartyid then it would update the customer address, in case of new Dirpartyid it would c reate a new address.
To Find or Update the customer primary Address in Ax 2012