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

Mark All for Open Cust Trans and Open Vend Trans

We have situations where there are lots of open transactions that need to be settled against each other. This can be the case if auto settlement is turned off. One solution is to add a "Mark All" button to the custOpenTrans or vendOpenTrans forms. This button "checks" the mark checkbox on every line. The user can then uncheck several lines if needed and Update to settle the lines. The code below is an example of what we used on the open vendor transaction screen. The code is very similar on the AR side. One note: I used vendTable.AccountNum in the code below. That should be generalized to work with any buffer that is passed into the open trans form. void customMarkAll() { VendTransOpen localVendTransOpen; VendTrans localVendTrans; container conSum; int linesProcessed; ; //show wait cursor startLengthyOperation(); element.lock(); //remove all prior markings specOffsetVoucher.deleteSpe...

Print Report in Microsoft Dynamics AX 2009 through X++

I am trying to print sales confirmation report on a button click which I have added on Sales Order Detail form in Microsoft Dynamics AX 2009. On click event of that button, I have written following code: void clicked() {     Args                args;     ReportRun           reportRun;     SalesFormLetter     salesFormLetter;     PrintJobSettings    printJobSettings;     CustConfirmJour     custConfirmJour;     RecordSortedList    list                = new RecordSortedList(55);     SalesTable          salesTableUpdate;     ;     SELEC...

Creating Free Text Invoice through X++ code

Job: Calling class from job to run the class public void freeTextInvoicePostTestJob() { Dialog dialog; DialogField dlgCustAcc; DialogGroup dialogPeriodLengthGroup, dialogPeriodLengthGroup1; DialogField dlgLedgerAcc; ; dialog = new Dialog("Free-Text Invoice"); dialogPeriodLengthGroup1 = dialog.addGroup('Cust Table'); dlgCustAcc = dialog.addField(typeid(CustAccount)); dialogPeriodLengthGroup = dialog.addGroup('Ledger Table'); dlgLedgerAcc = dialog.addField(typeid(LedgerAccount)); if(dialog.run()) { if(dlgCustAcc.value() && dlgLedgerAcc.value() != '') FreeTxtInvoiceCreatePost::main(dlgCustAcc.value(), dlgLedgerAcc.value()); else throw error(strfmt("Either CustAccount or LedgerAccount info is missing.")); } } Class: Which creates the free text invoice class FreeTxtInvoiceCreatePost { } static void main(CustAccount _custAccount, LedgerAccount _ledgerAccount) { CustInvoiceTable custInvoiceTable; ...