private static void Sample_Contact(ApxWS.ApxWS apxWS) { ApxWS.ContactQueryOptions queryOptions = new ApxWS.ContactQueryOptions(); ApxWS.ContactQueryResult queryResult; // You must already setup a contact with code "C1" ApxWS.Status status = apxWS.Contact_GetByContactCode(ref queryOptions, "D0U0100012", out queryResult); ApxWS.Contact contact = queryResult.ContactList[0]; contact._DBAction = ApxWS.DBAction.Update; contact._UpdatedFields = new ApxWS.ContactUpdatedFields(); // To clear a string field, set it to an empty string. contact.LastNameIsNull = false; contact._UpdatedFields.LastName = true; contact.LastName = contact.LastName; ApxWS.ContactPutOptions putOps = new ApxWS.ContactPutOptions(); ApxWS.ContactPutResult putRlt = new ApxWS.ContactPutResult(); status = apxWS.Contact_Put(ref putOps, contact, out putRlt); if (!status.Success) { Console.WriteLine(status.ExceptionText); } }
/// <summary> /// This sample include 3 cases for Salentica /// Case 1: Change default address from Home to Business /// Case 2: Update Home address line 2 to a new value "abc" /// Case 3: Clear Business address line 3 /// </summary> /// <param name="apxWS"></param> private static void Sample_ContactAddress(ApxWS.ApxWS apxWS) { ApxWS.ContactQueryOptions queryOptions = new ApxWS.ContactQueryOptions(); // To return addresses along with contact, you must set this field to true queryOptions.IncludeContactAddressList = true; ApxWS.ContactQueryResult queryResult; // Get a contact by contact code ApxWS.Status status = apxWS.Contact_GetByContactCode(ref queryOptions, "C1", out queryResult); if (status.Success) { ApxWS.Contact contact = queryResult.ContactList[0]; contact._DBAction = ApxWS.DBAction.Update; contact._UpdatedFields = new ApxWS.ContactUpdatedFields(); foreach (ApxWS.ContactAddress address in contact.ContactAddressList) { #region Case 1: Change default address from Home to Business // Assumption: default address was Home address if (address.AddressLabel == "Home") { // this is to indicate that Home address is to be updated address._DBAction = ApxWS.DBAction.Update; // this is to indicate that IsDefaultAddress is not null address.IsDefaultAddressIsNull = false; // this is to indicate that IsDefaultAddress is to be updated address._UpdatedFields.IsDefaultAddress = true; // this is to set IsDefault Address to false address.IsDefaultAddress = false; #region Case 2: Update Home address line 2 to a new value "abc" // this is to set new value to AddressLine2 address.AddressLine2 = "abc"; // this is to indicate that AddressLine2 is to be updated address._UpdatedFields.AddressLine2 = true; #endregion } //Assumption: new default address is Business address if (address.AddressLabel == "Business") { // this is to indicate that Business address is to be updated address._DBAction = ApxWS.DBAction.Update; // this is to indicate that IsDefaultAddress is not null address.IsDefaultAddressIsNull = false; // this is to indicate that IsDefaultAddress is to be updated address._UpdatedFields.IsDefaultAddress = true; // this is to set IsDefault Address to true address.IsDefaultAddress = true; #region Case 3: Clear Business address line 3 // this is to set new value to AddressLine2 address.AddressLine3 = string.Empty; // this is to indicate that AddressLine2 is to be updated address._UpdatedFields.AddressLine3 = true; #endregion } #endregion } ApxWS.ContactPutOptions putOps = new ApxWS.ContactPutOptions(); ApxWS.ContactPutResult putRlt = new ApxWS.ContactPutResult(); status = apxWS.Contact_Put(ref putOps, contact, out putRlt); if (!status.Success) { Console.WriteLine(status.ExceptionText); } } }
/// <summary> /// This sample shows how to clear fields /// </summary> /// <param name="apxWS"></param> private static void Sample_ClearContactFields(ApxWS.ApxWS apxWS) { ApxWS.ContactQueryOptions queryOptions = new ApxWS.ContactQueryOptions(); ApxWS.ContactQueryResult queryResult; // You must already setup a contact with code "C1" ApxWS.Status status = apxWS.Contact_GetByContactCode(ref queryOptions, "C1", out queryResult); ApxWS.Contact contact = queryResult.ContactList[0]; contact._DBAction = ApxWS.DBAction.Update; contact._UpdatedFields = new ApxWS.ContactUpdatedFields(); // To clear a string field, set it to an empty string. contact.LastNameIsNull = false; contact._UpdatedFields.LastName = true; contact.LastName = ""; // Or contact.LastName = String.Empty // To clear a date field, set it to the specific date "1/1/1753". contact.BirthdateIsNull = false; contact._UpdatedFields.Birthdate = true; contact.Birthdate = "1/1/1753 08:00:00Z"; // You must use UTC time here. // To clear a numeric field, set it to an invalid value. // For example, CallInterval must be a positive number between 0 and 32767, then -1 is invalid. contact.CallIntervalIsNull = false; contact._UpdatedFields.CallInterval = true; contact.CallInterval = -1; // To clear a numeric field that allows both positive and nagative values, set it to 0 will clear this field. contact.TaxBracketIsNull = false; contact._UpdatedFields.TaxBracket = true; contact.TaxBracket = 0; foreach (ApxWS.ApiCustomField field in contact.ContactCustomFields) { // You must already setup and activate a custom field in Date type if (string.Equals(field.Tag, "DateField", StringComparison.CurrentCultureIgnoreCase)) { // To clear a custom date field, set it to the specific date "1/1/1753". field.UpdatedField = true; field.ValueIsNull = false; field.Value = "1/1/1753 08:00:00z"; // You must use UTC time here. } // You must already setup and activate a custom field in Text type if (string.Equals(field.Tag, "TextField", StringComparison.CurrentCultureIgnoreCase)) { // To clear a custom string field, set it to an empty string. field.UpdatedField = true; field.ValueIsNull = false; field.Value = ""; // // Or field.Value = String.Empty } // You must already setup and activate a custom field in Numeric type if (string.Equals(field.Tag, "numField", StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("numField: {0}", field.Value); // To clear a custom numeric field, set it to -1.0E300. field.UpdatedField = true; field.ValueIsNull = false; field.Value = "-1.0E300"; // clear Numeric field } } ApxWS.ContactPutOptions putOps = new ApxWS.ContactPutOptions(); ApxWS.ContactPutResult putRlt = new ApxWS.ContactPutResult(); status = apxWS.Contact_Put(ref putOps, contact, out putRlt); if (!status.Success) { Console.WriteLine(status.ExceptionText); } }