web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

AX trying to create a new postal/zip code

(0) ShareShare
ReportReport
Posted on by 455

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?

I have the same question (0)
  • Verified answer
    Samy123 Profile Picture
    455 on at
    RE: AX trying to create a new postal/zip code

    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.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    297,462 Super User 2025 Season 2 on at
    RE: AX trying to create a new postal/zip code

    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.

  • Suggested answer
    Ajit Profile Picture
    8,755 on at
    RE: AX trying to create a new postal/zip code

    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'.

  • Suggested answer
    Satish Panwar Profile Picture
    14,669 Moderator on at
    RE: AX trying to create a new postal/zip code

    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.

  • Samy123 Profile Picture
    455 on at
    RE: AX trying to create a new postal/zip code

    CallStack.txt

    CAll Stack from visual studio attached

      

  • André Arnaud de Calavon Profile Picture
    297,462 Super User 2025 Season 2 on at
    RE: AX trying to create a new postal/zip code

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 756 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 629 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 514 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans