Dear All,
Today's am gonna share a code related to Customer Master Write operation.
In the sense inserting customers into AX thru the System Service.
Please follow the below steps as shown in screenshots.
1.Create Project in AOT and Add a Service Reference and Service Group Nodes into a created project as shown in below.
2.Create a new Service Reference as below and add the inbuilt service class for the service.
3.For Customer master CRUD operation there is class in Ax named as "
CustCustomerService".
select it in the property of a service reference and add the operation.
4.Once after adding the operation deploy the service and open VS.
5.In VS create new Windows Form Application Project and the URL to Service Reference as below.
5.Run the below code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CustomerMasterMasterWriteTest.CustomerCreate;
namespace CustomerMasterMasterWriteTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
CustomerCreate.CustomerMasterWriteClient proxy = new CustomerCreate.CustomerMasterWriteClient();
//CustomerCreate.CustomerMasterCreateServiceClient proxy = new CustomerCreate.CustomerMasterCreateServiceClient();
CustomerCreate.CallContext newcont = new CustomerCreate.CallContext();
newcont.Company = "mub";
CustomerCreate.AxdCustomer customer = new CustomerCreate.AxdCustomer();
CustomerCreate.AxdEntity_CustTable Custtable = new CustomerCreate.AxdEntity_CustTable();
Custtable.AccountNum = "998877";
Custtable.Currency = "USD";
Custtable.CustGroup = "20";
Custtable.OneTimeCustomer = CustomerCreate.AxdExtType_OneTimeCustomer.Yes;
Custtable.OneTimeCustomerSpecified = true;
//Create the party record
CustomerCreate.AxdEntity_DirParty_DirPerson party = new CustomerCreate.AxdEntity_DirParty_DirPerson();
party.NameAlias = "TestInsertion";
//Set the name fields
CustomerCreate.AxdEntity_PersonName personName = new CustomerCreate.AxdEntity_PersonName();
personName.FirstName = "Test";
personName.MiddleName = "Tester";
personName.LastName = "Newell";
//Add the names to the party record and set the name sequence
party.PersonName = new CustomerCreate.AxdEntity_PersonName[1] { personName };
party.NameSequence = "FirstLast";
//Create a postal address
CustomerCreate.AxdEntity_DirPartyPostalAddressView address = new CustomerCreate.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
CustomerCreate.AxdEntity_DirPartyContactInfoView electronicAddress = new CustomerCreate.AxdEntity_DirPartyContactInfoView();
electronicAddress.LocationName = "Contact Email";
electronicAddress.Type = CustomerCreate.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 CustomerCreate.AxdEntity_DirParty_DirPartyTable[1] { party };
Custtable.DirParty[0].DirPartyPostalAddressView = new CustomerCreate.AxdEntity_DirPartyPostalAddressView[1] { address };
Custtable.DirParty[0].DirPartyContactInfoView = new CustomerCreate.AxdEntity_DirPartyContactInfoView[1] { electronicAddress }; ;
//Add the CustTable record to the Customer entity
customer.CustTable = new CustomerCreate.AxdEntity_CustTable[1] { Custtable };
//Create the customer
proxy.create(newcont, customer);
}
}
}