Hi All,
I have a requirement to create and update customers such as dob,address etc.
Can I get some x++ code for this please?
Or any blog or link which has the code also fine please.
Please send me ax 2009 based code
Hi All,
I have a requirement to create and update customers such as dob,address etc.
Can I get some x++ code for this please?
Or any blog or link which has the code also fine please.
Please send me ax 2009 based code
Thanks Martin.. Let me try this and come back to you ,,,,,
Let me try to do the simplication for you. Remember, the currect question is about updating an address, not about all the other fields. Also, let me eliminate the second service class object.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using CustomerServiceReference; class Program { static void Main(string[] args) { new Program().Run(); } private void Run() { string accountNum = "Cust0001"; string newAddress = "the new address"; EntityKey[] entityKey = GetEntityKey(accountNum) using (CustomerServiceClient proxy = CreateServiceClient()) { AxdCustomer customer = proxy.read(entityKey); AxdEntity_CustTable custTable = customer.CustTable[0]; custTable.Address = newAddress; proxy.update(entityKey, customer); } } private CustomerServiceClient CreateServiceClient() { CustomerServiceClient proxy = new CustomerServiceClient(); proxy.ClientCredentials.Windows.AllowNtlm = true; proxy.ClientCredentials.UserName.UserName = ""; // Removed for security reasons proxy.ClientCredentials.UserName.Password = ""; // Removed for security reasons return proxy; } private EntityKey[] GetEntityKey(string accountNum) { KeyField field = new KeyField() { Field = "AccountNum", Value = accountNum }; EntityKey key = new EntityKey() { KeyData = new[] { field } }; return new[] { key }; } }
What happens if you run this code? Of course, don't forget to set input values. And sorry if there are some errors; I wrote the code in a mere text editor.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace UCQCustCustomerService { class Program { private static void updateCustomer(CustomerServiceReference.AxdCustomer customer) { CustomerServiceReference.AxdCustomer custRec; CustomerServiceReference.CustomerServiceClient updateCust = new CustomerServiceReference.CustomerServiceClient(); updateCust.ClientCredentials.Windows.AllowNtlm = true; updateCust.ClientCredentials.UserName.UserName = ""; // Removed for security reasons updateCust.ClientCredentials.UserName.Password = ""; // Removed for security reasons CustomerServiceReference.AxdEntity_CustTable custTable = customer.CustTable[0]; CustomerServiceReference.AxdEntity_CustTable custUpdate = new CustomerServiceReference.AxdEntity_CustTable(); CustomerServiceReference.AxdCustomer axCustomer = new CustomerServiceReference.AxdCustomer(); custUpdate.action = CustomerServiceReference.AxdEnum_AxdEntityAction.update; custUpdate.AccountNum = customer.CustTable[0].AccountNum; custUpdate.Address = customer.CusTable[0].Address; custUpdate.CustClassificationId = customer.CustTable[0].CustClassificationId; custUpdate.CustItemGroupId = customer.CustTable[0].CustItemGroupId; custUpdate.CustGroup = customer.CustTable[0].CustGroup; custUpdate._DocumentHash = customer.CustTable[0]._DocumentHash; custUpdate.LanguageId = customer.CustTable[0].LanguageId; custUpdate.Currency = customer.CustTable[0].Currency; custUpdate.PartyType = customer.CustTable[0].PartyType; custUpdate.TaxGroup = customer.CustTable[0].TaxGroup; axCustomer.CustTable = new CustomerServiceReference.AxdEntity_CustTable[1] { custUpdate }; CustomerServiceReference.EntityKey[] readCustKeys = new CustomerServiceReference.EntityKey[1]; readCustKeys[0] = new CustomerServiceReference.EntityKey(); readCustKeys[0].KeyData = new CustomerServiceReference.KeyField[1]; readCustKeys[0].KeyData[0] = new CustomerServiceReference.KeyField(); readCustKeys[0].KeyData[0].Field = "AccountNum"; readCustKeys[0].KeyData[0].Value = custUpdate.AccountNum; updateCust.update(readCustKeys, axCustomer); //CustomerServiceReference.AxdEntity_CustTable[1] { custUpdate }; // Create the entity key list for the request // readCustKeys[0].KeyData[0].Value = custUpdate.Address; // custRec = updateCust.read(readCustKeys); Console.WriteLine("Updated Address is : " custUpdate.Address); Console.WriteLine("*********************************************"); } enum AXGender { Blank, Male, Female, NotStated } static void Main(string[] args) { string male,female; CustomerServiceReference.CustomerServiceClient proxy = new CustomerServiceReference.CustomerServiceClient(); CustomerServiceReference.AxdCustomer custRec; proxy.ClientCredentials.Windows.AllowNtlm = true; proxy.ClientCredentials.UserName.UserName = ""; proxy.ClientCredentials.UserName.Password = ""; // Create the entity key list for the request CustomerServiceReference.EntityKey[] readCustKeys = new CustomerServiceReference.EntityKey[1]; readCustKeys[0] = new CustomerServiceReference.EntityKey(); readCustKeys[0].KeyData = new CustomerServiceReference.KeyField[1]; readCustKeys[0].KeyData[0] = new CustomerServiceReference.KeyField(); readCustKeys[0].KeyData[0].Field = "AccountNum"; // Promtp User for Cust Acc Console.WriteLine("Provide Customer Acc Number :"); // Add the result to the entity key value. readCustKeys[0].KeyData[0].Value = Console.ReadLine(); try { custRec = proxy.read(readCustKeys); // Display customer info before Change Console.WriteLine("For Customer: " custRec.CustTable[0].AccountNum); Console.WriteLine("DataAreaId is: " custRec.CustTable[0].DataArea); Console.WriteLine("Current Address is: " custRec.CustTable[0].Address); // After Customer Update Console.WriteLine("Provide Customer Acc Number to update :"); // Add the result to the entity key value. readCustKeys[0].KeyData[0].Value = Console.ReadLine(); Console.WriteLine("Update Address :"); //readCustKeys[0].KeyData[0].Value = Console.ReadLine(); custRec = proxy.read(readCustKeys); custRec.CustTable[0].Address = Console.ReadLine(); Console.WriteLine("Customer Group Id :"); custRec.CustTable[0].CustItemGroupId = Console.ReadLine(); Console.WriteLine("Customer Group :"); custRec.CustTable[0].CustGroup = Console.ReadLine(); updateCustomer(custRec); Console.ReadKey(); } catch (Exception e) { Console.WriteLine("Exception: " e.Message); Console.ReadKey(); proxy.Abort(); } //proxy.Close(); } } }
I have pasted by removing code which is not required. And now i need all this code. Please can suggest me how to pass address to customer from Console.Readline()
Could you please remove the code that isn't relavant to the question, the variable that aren't used at all and so on? It'll be then much easier to focus on the actual problem.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace UCQCustCustomerService { class Program { private static void updateCustomer(CustomerServiceReference.AxdCustomer customer) { CustomerServiceReference.AxdCustomer custRec; CustomerServiceReference.CustomerServiceClient updateCust = new CustomerServiceReference.CustomerServiceClient(); updateCust.ClientCredentials.Windows.AllowNtlm = true; updateCust.ClientCredentials.UserName.UserName = ""; // Removed for security reasons updateCust.ClientCredentials.UserName.Password = ""; // Removed for security reasons CustomerServiceReference.AxdEntity_CustTable custTable = customer.CustTable[0]; CustomerServiceReference.AxdEntity_CustTable custUpdate = new CustomerServiceReference.AxdEntity_CustTable(); CustomerServiceReference.AxdCustomer axCustomer = new CustomerServiceReference.AxdCustomer(); custUpdate.action = CustomerServiceReference.AxdEnum_AxdEntityAction.update; custUpdate.AccountNum = customer.CustTable[0].AccountNum; custUpdate.Address = customer.CusTable[0].Address; custUpdate.CustClassificationId = customer.CustTable[0].CustClassificationId; custUpdate.CustItemGroupId = customer.CustTable[0].CustItemGroupId; custUpdate.CustGroup = customer.CustTable[0].CustGroup; custUpdate._DocumentHash = customer.CustTable[0]._DocumentHash; custUpdate.LanguageId = customer.CustTable[0].LanguageId; custUpdate.Currency = customer.CustTable[0].Currency; custUpdate.PartyType = customer.CustTable[0].PartyType; custUpdate.TaxGroup = customer.CustTable[0].TaxGroup; axCustomer.CustTable = new CustomerServiceReference.AxdEntity_CustTable[1] { custUpdate }; CustomerServiceReference.EntityKey[] readCustKeys = new CustomerServiceReference.EntityKey[1]; readCustKeys[0] = new CustomerServiceReference.EntityKey(); readCustKeys[0].KeyData = new CustomerServiceReference.KeyField[1]; readCustKeys[0].KeyData[0] = new CustomerServiceReference.KeyField(); readCustKeys[0].KeyData[0].Field = "AccountNum"; readCustKeys[0].KeyData[0].Value = custUpdate.AccountNum; updateCust.update(readCustKeys, axCustomer); //CustomerServiceReference.AxdEntity_CustTable[1] { custUpdate }; // Create the entity key list for the request // readCustKeys[0].KeyData[0].Value = custUpdate.Address; // custRec = updateCust.read(readCustKeys); Console.WriteLine("Updated Address is : " custUpdate.Address); Console.WriteLine("*********************************************"); } enum AXGender { Blank, Male, Female, NotStated } static void Main(string[] args) { string male,female; CustomerServiceReference.CustomerServiceClient proxy = new CustomerServiceReference.CustomerServiceClient(); CustomerServiceReference.AxdCustomer custRec; proxy.ClientCredentials.Windows.AllowNtlm = true; proxy.ClientCredentials.UserName.UserName = ""; proxy.ClientCredentials.UserName.Password = ""; // Create the entity key list for the request CustomerServiceReference.EntityKey[] readCustKeys = new CustomerServiceReference.EntityKey[1]; readCustKeys[0] = new CustomerServiceReference.EntityKey(); readCustKeys[0].KeyData = new CustomerServiceReference.KeyField[1]; readCustKeys[0].KeyData[0] = new CustomerServiceReference.KeyField(); readCustKeys[0].KeyData[0].Field = "AccountNum"; // Promtp User for Cust Acc Console.WriteLine("Provide Customer Acc Number :"); // Add the result to the entity key value. readCustKeys[0].KeyData[0].Value = Console.ReadLine(); try { custRec = proxy.read(readCustKeys); // Display customer info before Change Console.WriteLine("For Customer: " custRec.CustTable[0].AccountNum); Console.WriteLine("DataAreaId is: " custRec.CustTable[0].DataArea); Console.WriteLine("Current Address is: " custRec.CustTable[0].Address); // After Customer Update Console.WriteLine("Provide Customer Acc Number to update :"); // Add the result to the entity key value. readCustKeys[0].KeyData[0].Value = Console.ReadLine(); Console.WriteLine("Update Address :"); //readCustKeys[0].KeyData[0].Value = Console.ReadLine(); custRec = proxy.read(readCustKeys); custRec.CustTable[0].Address = Console.ReadLine(); Console.WriteLine("Customer Group Id :"); custRec.CustTable[0].CustItemGroupId = Console.ReadLine(); Console.WriteLine("Customer Group :"); custRec.CustTable[0].CustGroup = Console.ReadLine(); updateCustomer(custRec); Console.ReadKey(); } catch (Exception e) { Console.WriteLine("Exception: " e.Message); Console.ReadKey(); proxy.Abort(); } //proxy.Close(); } } }
Please find whole console C# code as below:
I don't see anything like that in your code. Please add the relevant pieces to your code, remove the irrelevant ones (such as the other fields) and share your code with us.
No Martin, actually before assigning the address I am taking new address as input via Console.Readline() and then pass that to (customer) and then finally I assign it as below
custUpdate.Address = customer.CustTable[0].Address;
What change do you expect? It seems to me that you're assigning the address that the customer already has, therefore there is nothing to change.
CustomerServiceReference.AxdEntity_CustTable custTable = customer.CustTable[0]; CustomerServiceReference.AxdEntity_CustTable custUpdate = new CustomerServiceReference.AxdEntity_CustTable(); CustomerServiceReference.AxdCustomer axCustomer = new CustomerServiceReference.AxdCustomer(); custUpdate.action = CustomerServiceReference.AxdEnum_AxdEntityAction.update; custUpdate.AccountNum = customer.CustTable[0].AccountNum; custUpdate.PPTAusPostBillPayCode = customer.CustTable[0].PPTAusPostBillPayCode; custUpdate.CustClassificationId = customer.CustTable[0].CustClassificationId; custUpdate.Blocked = customer.CustTable[0].Blocked; custUpdate.CellularPhone = customer.CustTable[0].CellularPhone; custUpdate.ECL_ACMDateOfDeath = customer.CustTable[0].ECL_ACMDateOfDeath; custUpdate.ECL_ACMDVAPensionNo = customer.CustTable[0].ECL_ACMDVAPensionNo; custUpdate.ECL_ACMFirstName = customer.CustTable[0].ECL_ACMFirstName; custUpdate.ECL_ACMGender = customer.CustTable[0].ECL_ACMGender; custUpdate.CustItemGroupId = customer.CustTable[0].CustItemGroupId; custUpdate.CustGroup = customer.CustTable[0].CustGroup; custUpdate._DocumentHash = customer.CustTable[0]._DocumentHash; custUpdate.LanguageId = customer.CustTable[0].LanguageId; custUpdate.Currency = customer.CustTable[0].Currency; custUpdate.PartyType = customer.CustTable[0].PartyType; custUpdate.TaxGroup = customer.CustTable[0].TaxGroup; axCustomer.CustTable = new CustomerServiceReference.AxdEntity_CustTable[1] { custUpdate }; CustomerServiceReference.EntityKey[] readCustKeys = new CustomerServiceReference.EntityKey[1]; readCustKeys[0] = new CustomerServiceReference.EntityKey(); readCustKeys[0].KeyData = new CustomerServiceReference.KeyField[1]; readCustKeys[0].KeyData[0] = new CustomerServiceReference.KeyField(); readCustKeys[0].KeyData[0].Field = "AccountNum"; readCustKeys[0].KeyData[0].Value = custUpdate.AccountNum;
I have pasted my C# Code.
Its working fine for updating Customer cellular no and name etc.
But when address as below it is not updating though I dont get any errors:
custUpdate.Address = customer.CustTable[0.Address;
Could you please let me know what am I doing wrong here?
And I am taking address try Console.REadLine() and passing it
Sorry, I don't have that particular piece of code for that particular version of AX.
But I (and others) could help if you explain your particular problem.
You said that you have a problem with the address - does it mean that you know how to update other information, such as customer name?
What exactly are struggling with?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156