Hello,
I am trying to create a customer in AX with a postal address using AIF. The problem is AX is throwing following exception
Cannot create a record in ZIP/postal codes (LogisticsAddressZipCode). ZIP/postal code: 66202, USA.
The record already exists.
My service code looks like this:
AXCustomerService.AxdEntity_DirPartyPostalAddressView address = new AXCustomerService.AxdEntity_DirPartyPostalAddressView();
address.LocationName = "Address";
address.Street = _street;
address.City = _city;
address.State = _state;
address.CountryRegionId = _country;
address.ZipCode = _zip;
address.Roles = @"Delivery;Invoice;Marketing";
address.IsPrimary = AXCustomerService.AxdExtType_LogisticsIsPrimaryAddress.Yes;
address.IsPrimarySpecified = true;
AXCustomerService.AxdEntity_DirParty_DirOrganization dpt = new AXCustomerService.AxdEntity_DirParty_DirOrganization();
dpt.Name = "ABC Company";
dpt.DirPartyPostalAddressView = new AXCustomerService.AxdEntity_DirPartyPostalAddressView[1] { address };
AXCustomerService.AxdEntity_CustTable custTable = new AXCustomerService.AxdEntity_CustTable();
custTable.CustGroup = "FBO";
custTable.DirParty = new AXCustomerService.AxdEntity_DirParty_DirPartyTable[1] { dpt };
AXCustomerService.AxdCustomer customer = new AXCustomerService.AxdCustomer();
customer.CustTable = new AXCustomerService.AxdEntity_CustTable[1] { custTable };
AXCustomerService.EntityKey[] keysCustomer = null;
keysCustomer = client.create(context, customer);
when code client.create(context, customer); executes AX throws exception stated in the beginning, my concern is that why AX is even calling insert method on LogisticsAddressZipCode table? it should only be creating a record in DirPartyPostalAddressView.
Any ideas?
Thanks everyone for your replies,
Andre: Yes for some reason there is custom index that prohibits duplicate on combination of countryRegionId and ZipCodeId, may be some legacy logic.
I found out that in few instances cities tied to zipcodes in AX are not correct. So when AX did not find zip, city, state combination it tried to create a new record in LogisticsAddressZipCode table and there was already a record for the entered zip code but tied to a different city. So I added couple of lines of code in that class when all else fail find LogisticsAddressZipCode by just ZipCode and and then call LogisticsPostalAddressMap::initFromZipCode(logisticsAddressZipCode) and get the city from AX for that zipcode. So in this way I avoided the conflict and picking AX city over entered city.
Hi Samy,
The coding in CreatePostalAddress is trying to find an existing postal code. Otherwise it will insert a new one.
All indexes on the table LogisticsAddressZipcode are set to allow duplicates in the standard application. Can you review if there are custom or changed indexes on this table? The only unique index on this table is the RecId index. If there are no changes, there should be an issue with the RecId generation for this table.
Is this happening for any zip code? Please try what Satish has suggested. If it is happening for any zip code then I would check if system is trying to use the existing recid for table 'LogisticsAddressZipCode'.
Hi Sami,
Can you check if the exact record you are sending for zipcode already exists in AX? Another option is try to send a Zip that doesn't exists and see if it gets created. Then make the same call again and see if the error still pops up.
Hi Samy,
What is the 'client' variable here? Possibly, you can use the AX debugger or Visual Studio debugger to find out what call stack is used to insert the ZIP/postal code.
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