City is not updated while updating Zipcode

Hi Experts,

I have a runnable job to update the primary address based on inventlocation. When i was manually adding zip code in the address, corresponding city is automatically updated. But via x++ Runnable class, city is not updated.

Below is my sample code, for this actually ‘aaa’ city needs to be updated but it’s not happening.
Manually its working.

LogisticsPostalAddress logPostAddr;
logPostAddr.selectforupdate(true) ;
ttsbegin;
logPostAddr. ZipCode= 123;
logPostAddr. Update() ;
ttscommit;

Please guide me on this one.

Thanks in Advance,
Mark

@MartinDrab Do you have any suggestions on this one.

The problem is obvious - you update ZipCode only and your code doesn’t include the logic you ask for. The only way how it could magically happen is if it was implemented in update() ( because that’s the only method you call), but it isn’t the case. You need to call modifiedFieldZipCode() after setting ZipCode and before updating the record.

The form calls modifiedField() method, which then calls modifiedFieldZipCode(). But if you write code, it’s up to you to call what you want.

By the way, your code won’t work anyway, because you’re trying to update a record that you’ve never selected. Either use a find*() method with the _update parameter set to true, or use select forUpdate statement. Do it in the same transaction as the update. Then you can also throw away your call of selectForUpdate() method.

Thanks a lot @MartinDrab!! :slightly_smiling_face: