Skip to main content

Importing Customers, Vendors and Products in AX 2012

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 = "beckynewell@madeup.com";
            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 -http://blogs.msdn.com/b/dynamicsaxscm/archive/2011/07/06/product-item-data-management-services.aspx

Popular posts from this blog

Dynamics Axapta: Sales Orders & Business Connector

Well, again folllowing my same idea of writting close to nothing and pasting code, I'll paste in some code to create a sales order from some basic data and the invoice it. I'll try to explain more in the future. AxaptaObject axSalesTable = ax.CreateAxaptaObject("AxSalesTable"); AxaptaRecord rcInventDim = ax.CreateAxaptaRecord("InventDim"); AxaptaRecord rcCustTable = ax.CreateAxaptaRecord("CustTable"); rcCustTable.ExecuteStmt("select * from %1 where %1.AccountNum == '" + MySalesOrderObject.CustAccount + "'"); if (MySalesOrderObject.CurrencyCode.Trim().Length == 0) MySalesOrderObject.CurrencyCode = rcCustTable.get_Field("Currency").ToString().Trim(); string sTaxGroup = rcCustTable.get_Field("taxgroup").ToString().Trim(); //set header level fields axSalesTable.Call("parmSalesName", MySalesOrderObject.SalesName.Trim()); axSalesTable.Call("parmCustAccount", M

Passing values between form and class

Class name is EmplDuplication and Form is EmplTable . void clicked() {    MenuFunction mf;    args args = new Args();    ;     args.record(EmplTable);     mf = new menufunction(identifierstr(EmplDuplication), MenuItemType::Action); mf.run(args); } Meanwhile, in the main() method of the EmplDuplication class, we need to put this Axapta x++ code to get the datasource: static void main(Args args) {     EmplDuplication EmplDuplication; EmplTable localEmplTable; ;     if(args.record().TableId == tablenum(EmplTable)) localEmplTable = args.record();     ... }