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

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();     ... }

What does this mean: "The form datasource query object does not support changing its AllowCrossCompany property after the form has executed the query."?

I have made a form with datasources vendtable and vendtrans. Inside vendtable_ds.executequery() looks like this: QueryBuildDataSource queryBuildDatasource ,queryBDS_VendTrans_Invoice; ; queryBuildDatasource = this.query().dataSourceTable(tablenum(vendtable)); queryBDS_VendTrans_Invoice = this.query().dataSourceTable(tablenum(vendtrans)); if (curext() == "MASTERCOMP") { this.query().allowCrossCompany(true); } else { this.query().allowCrossCompany(false); } //FilterVendorName = stringedit control on form if (FilterVendorName.text()) { queryBuildDatasource.addRange(fieldNum(VendTable,Name)).value(strfmt("*%1*", FilterVendorName.text())); } else { queryBuildDatasource.clearRange(fieldNum(VendTable,Name)); } //FilterInvoiceNumber = stringedit control on form if (FilterInvoiceNumber.valueStr() == "") { queryBDS_VendTrans_Invoice.enabled(false); } else { queryBDS_VendTrans_Invoice.enabled(true); queryBDS_VendTrans_In...