How to Edit address using X++ in AX 2012 ?

I have a address filled corresponding to a Customer record in AX 2012. Now, My requirement is to Select Address from Address tab of a Edit Customer form and then to update the same using X++ Code… I have tried to perform below code after passing current Party and Location ID…

obj_DirParty = DirParty::constructFromPartyRecId(obj_partyTable.RecId );    
  obj_DirParty.createOrUpdatePostalAddress(obj_postalAddress, formRun.purposecon()

But it is throwing error saying… Microsoft Dynamics AX Views are read only. So ultimately I have to press ESC button to disallow changes, however a new record is being added in a DirpartyPostalAddressView and I am able to see my changes before pressing ESC in a form. But after pressing ESC, Chages being made to LogisticsLocation table record changes to previous data. My question is How to avoid this error so I can get my updated data in a form.

Hi Mohd,

You can use below code.

LogisticsPostalAddress address;

custtable = Custtable::find(“1101”);

address.Street = “Teststreet”;
address.ZipCode = “89298”;
address.City = “testcity”;

addressView.Party = CustTable.Party;
addressview.initFromPostalAddress(address);

DirParty = DirParty::constructFromPartyRecId(CustTable.Party);
roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery).RecId];

DirParty.createOrUpdatePostalAddress(addressView,roles);

Best Regards,

Jagananth Tripathy

Hi Jagan,

Thanks for replying, But as much as I know…above code will insert new address with new location Id and everything else.

Whereas I need to Edit the Current address.

Please correct me if i am wrong.

Hi Mohd,

createOrUpdatePostalAddress method is useful for both creating or updating the customer address. if you provide the existing dirpartyid then it will update the customer address ,in case of new dirpartyid it will create a new address.

Best Regards,

Jagannath Tripathy

wel Let me put everything what I did there…

first of all I have one form from where I have to update Current Adresss.

I have created menuitem for that form and placed it on the address tab of Edit Customer form,

After that I set the datasource of a menuitem as DirPartyPostalAddressView(view in Edit customer form) to get current locationid and Party on a button click.

Now, On the init of my form…

I have written code as:

obj_postalAddress = _args.record(); //to get current record reference

intpartyid = obj_postalAddress.Party;

intLocationId = obj_postalAddress.Location;

Then passed some parameters as:

obj_postalAddress.CountryRegionId = “AUS”;

Finally wrote above 2 lines of code and getting the error as “Microsoft Dynamics AX views are read only”

I don’t know, where in above code i am trying to update view…?

did any one got answer for this?? i am also facing the same problem… when ever trying to update the address a new line is created