Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

AX trying to create a new postal/zip code

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?

  • Verified answer
    Samy123 Profile Picture
    Samy123 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
    André Arnaud de Cal... 291,240 Super User 2024 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
    Ajit 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
    Satish Panwar 14,645 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
    Samy123 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
    André Arnaud de Cal... 291,240 Super User 2024 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans