Microsoft Dynamics AX Support

This blog contains posts by the Microsoft Dynamics AX Support teams Worldwide

Importing Customers, Vendors and Products in AX 2012

Importing Customers, Vendors and Products in AX 2012

Rate This
  • Comments 15

People are starting to get into 2012 and I couldn't be happier about it!!  There is a lot of interest in services so I decided to write a couple different simple examples of how to call document services in AX.  I apologize for the formatting of code in this text editor, I promise when I wrote it, it looked like normal code :)

This calls the vendor service:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using ConsoleApplication9.Vendors;

namespace ConsoleApplication9


    class Program


        static void Main(string[] args)


            VendTableServiceClient proxy = new VendTableServiceClient();

            CallContext context = new CallContext();

context.Company = "ceu";  //New class that replaces AX endpoints.  It makes it obvious which company you are importing data into.  I love this class!!


            AxdVendTable vendor = new AxdVendTable();

             AxdEntity_VendTable[] vendTables = new AxdEntity_VendTable[1];

            AxdEntity_VendTable vendTable = new AxdEntity_VendTable();

            //vendTable.AccountNum = "877778";  //If your number sequences for vendor accounts are set to manual set this property           
vendTable.Currency = "USD";           
vendTable.VendGroup = "10";

vendTable.Name = "My Vendor Test Name";


            //Create the party record

            AxdEntity_DirPartyTable_DirPerson party = new AxdEntity_DirPartyTable_DirPerson();

party.NameAlias = "First2";


            //Set the name fields

            AxdEntity_PersonName personName = new AxdEntity_PersonName();

personName.FirstName = "First2";

personName.MiddleName = "Middle2";

personName.LastName = "Last2";


            //Add the names to the party record and set the name sequence

party.PersonName = new AxdEntity_PersonName[1] { personName };

party.NameSequence = "FirstLast";           
vendTable.DirPartyTable = new AxdEntity_DirPartyTable_DirPartyTable[1] { party };



            vendTables[0] = vendTable;

vendor.VendTable = vendTables;


proxy.create(context, vendor);






This one is for customers:

            CustomerServiceClient proxy = new CustomerServiceClient();
            CallContext context = new CallContext();
            context.Company = "ceu";

            AxdCustomer customer = new AxdCustomer();

            AxdEntity_CustTable custTable = new AxdEntity_CustTable();
            custTable.AccountNum = "998877";
            custTable.Currency = "USD";
            custTable.CustGroup = "20";
            custTable.OneTimeCustomer = AxdExtType_OneTimeCustomer.Yes;
            custTable.OneTimeCustomerSpecified = true;

            //Create the party record
            AxdEntity_DirParty_DirPerson party = new AxdEntity_DirParty_DirPerson();
            party.NameAlias = "Becky";

            //Set the name fields
            AxdEntity_PersonName personName = new AxdEntity_PersonName();
            personName.FirstName = "Becky";
            personName.MiddleName = "ILiveForThis";
            personName.LastName = "Newell";

            //Add the names to the party record and set the name sequence
            party.PersonName = new AxdEntity_PersonName[1] { personName };
            party.NameSequence = "FirstLast";

            //Create a postal address
            AxdEntity_DirPartyPostalAddressView address = new AxdEntity_DirPartyPostalAddressView();
            address.LocationName = "Location Name";
            address.Street = "2122 NE 5th St";
            address.City = "Beverly Hills";
            address.State = "CA";
            address.CountryRegionId = "USA";
            address.ZipCode = "90210";
            address.Roles = "Home;Delivery";

            //Create an electronic address
            AxdEntity_DirPartyContactInfoView electronicAddress = new AxdEntity_DirPartyContactInfoView();
            electronicAddress.LocationName = "Contact Email";
            electronicAddress.Type = AxdEnum_LogisticsElectronicAddressMethodType.Email;
            electronicAddress.TypeSpecified = true;
            electronicAddress.Locator = "";
            electronicAddress.Roles = "Home";

            //Add the addresses to the party record and the party to the CustTable record
            custTable.DirParty = new AxdEntity_DirParty_DirPartyTable[1] { party };
            custTable.DirParty[0].DirPartyPostalAddressView = new AxdEntity_DirPartyPostalAddressView[1] { address };
            custTable.DirParty[0].DirPartyContactInfoView = new AxdEntity_DirPartyContactInfoView[1] { electronicAddress };

            //Add the CustTable record to the Customer entity
            customer.CustTable = new AxdEntity_CustTable[1] { custTable };

            //Create the customer
            proxy.create(context, customer);


For items you want to go out to this blog which shows you how to import items -

Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post
  • Thanks for the article

    Do you know how to add an address to an existing customer?

    Do you know how to update an existing address?, while trying to do this I always get Invalid Entity Action or Entity action cannot be specified.

    Thanks again!

  • You should have a look at the article I wrote on this blog regarding updates -

    The method below will add an address to an existing customer:

    private static void addAddressToExistingCustomer(AxdCustomer customer)


               CustomerServiceClient proxy = new CustomerServiceClient();

               CallContext context = new CallContext();

               context.Company = "ceu";

               AxdEntity_CustTable custTable = customer.CustTable[0];

               AxdCustomer axdCustomer2 = new AxdCustomer();

               axdCustomer2.ValidTimeStateType = customer.ValidTimeStateType;

               axdCustomer2.ValidTimeStateTypeSpecified = true;

               axdCustomer2.ValidAsOfDateTime = customer.ValidAsOfDateTime;

               axdCustomer2.ValidFromDateTime = customer.ValidFromDateTime;

               axdCustomer2.ValidToDateTime = customer.ValidToDateTime;

               AxdEntity_CustTable custTableNew = new AxdEntity_CustTable();

               custTableNew._DocumentHash = custTable._DocumentHash;

               custTableNew.RecId = custTable.RecId;

               custTableNew.RecVersion = custTable.RecVersion;

               custTableNew.action = AxdEnum_AxdEntityAction.update;

               custTableNew.actionSpecified = true;

               custTableNew.CreditMax = custTable.CreditMax + 10;

               custTableNew.CreditMaxSpecified = true;

               custTableNew.CustGroup = custTable.CustGroup;

               //Update the postal addresses

               AxdEntity_DirParty_DirOrganization dirPartyTable = (AxdEntity_DirParty_DirOrganization)custTable.DirParty[0];

               AxdEntity_DirParty_DirOrganization organizationNew = new AxdEntity_DirParty_DirOrganization();

               organizationNew.RecId = dirPartyTable.RecId;

               organizationNew.RecIdSpecified = true;

               organizationNew.RecVersion = dirPartyTable.RecVersion;

               organizationNew.RecVersionSpecified = true;

               organizationNew.action = AxdEnum_AxdEntityAction.update;

               organizationNew.actionSpecified = true;

               AxdEntity_DirPartyPostalAddressView newAddress = new AxdEntity_DirPartyPostalAddressView();

               newAddress.LocationName = "New Location Name";

               newAddress.Street = "1800 NE 5th St";

               newAddress.City = "Beverly Hills";

               newAddress.State = "CA";

               newAddress.CountryRegionId = "USA";

               newAddress.ZipCode = "90210";

               newAddress.Roles = "Home";

               newAddress.action = AxdEnum_AxdEntityAction.create;

               newAddress.actionSpecified = true;

               organizationNew.DirPartyPostalAddressView = new AxdEntity_DirPartyPostalAddressView[1] { newAddress };

               custTableNew.DirParty = new AxdEntity_DirParty_DirPartyTable[1] { organizationNew };

               axdCustomer2.CustTable = new AxdEntity_CustTable[1] { custTableNew };



                   proxy.update(context, Program.readCritera("1104"), axdCustomer2);




               catch (Exception e)






  • Hi,

    I am trying to add contact info to an existing customer (trying to attach the contact info at the postal address level and not customer(party) level ).

    I was able to successfully follow this tutorial :

    to add new contact info but have found no way to associate it to a particular address using the web service.

    I believe in AX, the LogisticsLocation.ParentLocation field needs to be populated with the desired postal address rec id.

    Also I would like to know if there is a way to do this when creating a new customer.

    Any help would be apprciated.


  • Hi Charu,

    Where in the AX UI would you do the equivalent of what you are trying to do with the service?  How would I enter a new contact on an existing customer at the postal address level in the UI?  That will help me understand and answer your question.

  • Hi  Becky,

    Open any customer details page. Under the addresses fast tab, add/edit an address, the Edit Address form opens up. I am trying to add contact information here under the contact info fast tab.


  • Hi Charu,

    I'm pretty sure you won't be able to set a contact on an address on the customer service without modifying the service.  Out-of-the-box I don't see anything in the data policy of the service that suggests you could create that contact through the service call.

  • Hi Becky,

    Thanks for looking into that. I am now exploring/using the newly released data migration framework tool (beta) instead, it gets the job done.

  • Received an email asking me how to create multiple products using the EcoResProductService.  The method below works for me:

    public void createMultipleProductsWithoutReleasing()


               EcoResProductServiceClient service = new EcoResProductServiceClient();

               CallContext ctx = new CallContext();

               ctx.Company = "ceu";

               AxdEcoResProduct axdProduct = new AxdEcoResProduct();

               AxdEntity_Product_EcoResProduct[] products = new AxdEntity_Product_EcoResProduct[10];

               for (int i = 0; i < 10; i++)


                   AxdEntity_Product_EcoResDistinctProduct distinctProduct = new AxdEntity_Product_EcoResDistinctProduct();

                   distinctProduct.DisplayProductNumber = "BulbW" + i.ToString();

                   distinctProduct.ProductType = AxdEnum_EcoResProductType.Item;

                   distinctProduct.SearchName = distinctProduct.DisplayProductNumber;

                   AxdEntity_Translation tran = new AxdEntity_Translation();

                   tran.LanguageId = "en-us";

                   tran.Name = "Transparent Bulb W" + i.ToString();

                   distinctProduct.Translation = new AxdEntity_Translation[1] { tran };

                   AxdEntity_Identifier ident = new AxdEntity_Identifier();

                   ident.ProductNumber = "BulbW" + i.ToString();

                   distinctProduct.Identifier = new AxdEntity_Identifier[1] { ident };

                   AxdEntity_StorageDimGroup storage = new AxdEntity_StorageDimGroup();

                   storage.Product = "BulbW" + i.ToString();

                   storage.StorageDimensionGroup = "PG_30";

                   distinctProduct.StorageDimGroup = new AxdEntity_StorageDimGroup[1] { storage };

                   AxdEntity_TrackingDimGroup tracking = new AxdEntity_TrackingDimGroup();

                   tracking.Product = "BulbW" + i.ToString();

                   tracking.TrackingDimensionGroup = "PG_30";

                   distinctProduct.TrackingDimGroup = new AxdEntity_TrackingDimGroup[1] { tracking };

                   products[i] = distinctProduct;


               axdProduct.Product = products;



                   service.create(ctx, axdProduct);


               catch (Exception e)






  • Thanks very much for your blog it is realy very helper, but i have an error and I don't know why

    when I try to import a vendor it run ok and i searched for this vendor in the screen and found it, after that i tried to edit it  so I found that his name is disabeared and the system asked me to add first, middle, last name since its mandatory, and when i tried to change them on the screen the system give me an error

  • Hi Mohamed,

    I just tested it.  After importing I went to AP > Common > All Vendors > Foud First2 Middle2 Last2 in the grid and clicked Edit.  In the form that opens I see the First name, Middle name and Last name fields are set.  If I click the Change name button I can alter each of these.  It looks correct to me.  

    I am using kernel and application build 6.0.1108.670.

  • Hi,

    I find your examples very useful.

    I still can not figure out how to assign telephone, email, fax etc. to one of contact addresses not just to customer. Any ideas?

  • Hi Jack,

    I don't understand your question.  Are you calling the customer service or the contact service?  Can you post the code you are using and where you want to change it?

  • Please post code for barcodes for relevant released product

  • Which service did you use in your app here?  

  • Hi Becky Newell,

    Is there any possible way to update the address information for a existing customer which is not primary?

Page 1 of 1 (15 items)