Custom New Customer X++ EventHandler


i want to add +1 behavior to the normal eventhandler of the creation of a new customer in my AX 2012 R2 application.

On create of the customer and post-creation i want to call a webservice hosted on IIS passing the account number.

Any idea guys?

Thanks in Advance…

Hi Ali,

Could you please elaborate whether you need to consume external webservice while creating customer manually in ax.

Hello Jagannath,

well i built my webservice in VS2010 and it is hosted on IIS (this is for integration purposes - i will need to call a method in the webservice passing also the account number for example using the url: http://myserver:port/myWebservice/myMethod?id=AccountNumber).

I managed to add custom Event handler on the insert method of the customer but how can i call this webservice?


Hi Ali,

First you need to create class in visual studio then in reference node you have to add service reference URL. Then you need to call the class library in your customer insert method and pass the customer account number as parameter in webservice.

Let me know if you have doubt

how to do this please refer below link

ok thank you Jagannath i will try that,

another question, do you have a sample code of updating a customer in AX 2012 using his account number?

I have written the code, but i am getting the following error on the service.update(context, entityKey, customer):

{System.ServiceModel.FaultException: Exception of type ‘Microsoft.Dynamics.Ax.Xpp.InvalidRemoteCallException’ was thrown.

Server stack trace:

at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)

at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

at WebApplication1.CustomerService.CustomerService.update(CustomerServiceUpdateRequest request)


thank you…

Hi Ali,

What I suggest you need to find out where is the triggering point.

Lets for example, you have two erp applications 1. Microsoft DAX 2. Microsoft CRM Now if triggering point is CRM then AX needs to provide webservice and vice versa.

If you are creating web service then there is no need of consuming the same you need to provide it to others.

However you can refer below link for reference

Hello Jagannath,

Below is my code:

CustomerServiceClient proxy = new CustomerServiceClient();


CallContext context = new CallContext();

context.Company = “MTR”;// ConfigurationManager.AppSettings[“AxOrganization”].ToString();

context.LogonAsUser = “ALBORJ"Administrator”;

AxdCustomer customer = new AxdCustomer();

AxdEntity_CustTable cust = new AxdEntity_CustTable();

cust.AccountNum = accountNumber;

cust.Currency = Currency;

cust.CustGroup = “custgroup”;

cust.OneTimeCustomer = AxdExtType_OneTimeCustomer.Yes;

cust.OneTimeCustomerSpecified = true;

//Create the party record

AxdEntity_DirParty_DirOrganization party2 = new AxdEntity_DirParty_DirOrganization();

party2.NumberOfEmployees = 0;

party2.NameAlias = fullName;

party2.Name = fullName;

//Create a postal address

AxdEntity_DirPartyPostalAddressView address = new AxdEntity_DirPartyPostalAddressView();

address.LocationName = descAddress; // descAddress;

address.Street = strAddress;

address.City = " ";

address.State = " ";

address.CountryRegionId = country;

address.Roles = “Business”;

AxdExtType_EffectiveDateTime myDateTime = new AxdExtType_EffectiveDateTime();

myDateTime.localDateTime = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString());

myDateTime.localDateTimeSpecified = true;

myDateTime.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;

myDateTime.timezoneSpecified = true;

address.ValidFrom = myDateTime;

AxdExtType_ExpirationDateTime expireDateTime = new AxdExtType_ExpirationDateTime();

expireDateTime.localDateTime = Convert.ToDateTime(DateTime.Now.AddYears(100).ToString());

expireDateTime.localDateTimeSpecified = true;

expireDateTime.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;

expireDateTime.timezoneSpecified = true;

address.ValidTo = expireDateTime;

cust.DirParty = new AxdEntity_DirParty_DirPartyTable[1] { party2 };

cust.DirParty[0].DirPartyPostalAddressView = new AxdEntity_DirPartyPostalAddressView[1] { address };

customer.CustTable = new AxdEntity_CustTable[1] { cust };

EntityKey[] ret = proxy.create(context, customer);

I am receiving the error that i mentioned before on the proxy.create line of code. Please advise…