cancel
Showing results for 
Search instead for 
Did you mean: 

Update Business Partner Address

hritondale
Explorer

I am having issues updating document addresses.

What I need to do:

I need to ensure that, at the moment when a Document (such as Sales Order, Customer Invoice, Customer Invoice Request) is generated, the Ship From - Ship To Address are validated. The validation process returns a valid address and, my plan is to fix the invalid address in runtime in order to save the correct one.

I am aware that the AddressSnapshot object is readonly once it is saved, so my plan was to make this change BEFORE the AddressSnapshot is saved. However, although the ABSL allows me to update Address fields. changes are never saved!!!!

Specifically, I need to be able to change values such as Postal Code / Region / City Name.

What I have tried:

I have tried to place my code in ALL events from the Extension Object AddressSnapshot

  • Node Root: AfterModify, BeforeSave
  • Node Postal Address: AfterModify, BeforeSave
  • Node Formatted Address: AfterModify, BeforeSave

I have also tried to place my code in the BeforeSave event of the Extension Object Business Partner.

In all cases, as I mentioned before, even though I am able to modify the values BEFORE the object is saved. if I look at the object that is actually saved, I don't see that my changes were taken (I see the old values).

I have also tried to make my validation on the OnSave event of the document where the address is used and I see a message saying that the AddressSnapshot was already saved. I understand that, but, is there any way I could at least generate a new AddressSnapshot?

My final test included a procedure placed in a action of a custom object. I was retrieven the whole Business Partner and then validating the address, but again, I couldn't save my changes.

Is there any way to do this?

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

thiago
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Hector,

I managed to update BP address with this code below, on the before.save of the AP.CRM.Global:SalesOrder

this.BillToParty.Party.BusinessPartner.AddressInformation.Address.DefaultPostalAddressRepresentation.GetFirst().CityName = "Hector";

Please, notice this is a quick test and I'm getting the first record just to show you how to get there.

I added new SO and it updated BP's address:

However, the SO snapshot still holds the old address information - you may think now on how to update the recently created SO with the updated address.

HTH,
Thiago.

Answers (3)

Answers (3)

hritondale
Explorer

Thank you very much Thiago.

It worked like a charm.

I was able to place the same code in the BeforeSave event of the root node in the BusinessPartner object

Kind regards!

hritondale
Explorer
0 Kudos

Thank you for your response Lewis.

We assume that an external organism have all the valid addresses.

I have tried to update the Address at Business Partner level as well but I haven't got good results. Although I am able to modify the values, the updates performed via code ABSL are not saved!

For instance, If I placed my "changing address" code in the BeforeSave event of the BusinessPartner address. The address is updated but, when I retrieve the BP, my changes are not there.

former_member183363
Active Contributor
0 Kudos

Hector,

Surely the ship-from and ship-to addresses come from the relevant parties and are thus always valid? If you want to change the address then you should probably just update the various business partners/customers/parties, rather than trying to set an address in the order itself.

Lewis