How to add/update/delete Customer Contact using CTAPI Customers web service


if (myCustomer == null)
{
 MessageBox.Show("You must load a valid customer first!");
 return;
}

//Sample Add custcontact
var myCustContact = myCustomersService.getNewCustContact(null);
myCustContact.CustID = myCustomer.CustID;//required
myCustContact.ContactID = System.Guid.NewGuid().ToString().Substring(0, 8);//required, unique by custID
myCustContact.Name = "Test Name";
myCustContact.Addr1 = "1 Test Rd";
myCustContact.EmailAddr = "test@catalinatechnology.com";
myCustContact.City = "somecity";
myCustContact.State = "CA";
myCustContact.Zip = "90210";
myCustContact.Country = "US";

myCustContact = myCustomersService.editCustContact("ADD", myCustContact);
if (myCustContact.errorMessage.Trim() != "")
{
 MessageBox.Show("Error doing Add: " + myCustContact.errorMessage);
 myCustContact.errorMessage = "";
 return;
}
else
{
 MessageBox.Show("Added: CustID:" + myCustContact.CustID + "; ContactID: " + myCustContact.ContactID);
 MessageBox.Show(ctStandardLib.ctHelper.serializeObject(myCustContact));
}

//Sample Update custcontact
var outParms = new System.Collections.Generic.List<ctDynamicsSL.customers.nameValuePairs>();
{
 var outParm = new ctDynamicsSL.customers.nameValuePairs();
 outParm.name = "CUSTID";
 outParm.value = myCustomer.CustID;
 outParms.Add(outParm);
}

{
 var outParm = new ctDynamicsSL.customers.nameValuePairs();
 outParm.name = "CONTACTID";
 outParm.value = myCustContact.ContactID;
 outParms.Add(outParm);
}

myCustContact = myCustomersService.getCustContacts(0, 0, outParms.ToArray())[0];//we are just going to select the first one found
myCustContact.Name = "Updated: " + myCustContact.Name;

myCustContact = myCustomersService.editCustContact("UPDATE", myCustContact);
if (myCustContact.errorMessage.Trim() != "")
{
 MessageBox.Show("Error doing update: " + myCustContact.errorMessage);
 myCustContact.errorMessage = "";
 return;
}
else
{
 MessageBox.Show("Updated: CustID:" + myCustContact.CustID + "; ContactID: " + myCustContact.ContactID);
 MessageBox.Show(ctStandardLib.ctHelper.serializeObject(myCustContact));
}


//Sample Delete custcontact
var tmpCustID = myCustContact.CustID;
var tmpContactID = myCustContact.ContactID;
myCustContact = new ctDynamicsSL.customers.CustContact();
myCustContact.CustID = tmpCustID;
myCustContact.ContactID = tmpContactID;

myCustContact = myCustomersService.editCustContact("DELETE", myCustContact);
if (myCustContact.errorMessage.Trim() != "")
{
 MessageBox.Show("Error doing delete: " + myCustContact.errorMessage);
 myCustContact.errorMessage = "";
 return;
}
else
{
 MessageBox.Show("Deleted: CustID:" + tmpCustID + "; ContactID: " + tmpContactID);
 MessageBox.Show(ctStandardLib.ctHelper.serializeObject(myCustContact));
}