/// <summary> /// Set all those properties of this outlook item whose values are different from the /// equivalent values on this CRM item. Update the synchronisation properties only if some /// other property has actually changed. /// </summary> /// <param name="crmItem">The CRM item from which to take values.</param> /// <param name="olItem">The Outlook item into which to insert values.</param> /// <returns>true if anything was changed.</returns> private void SetOutlookItemPropertiesFromCrmItem(EntryValue crmItem, Outlook.ContactItem olItem) { try { olItem.FirstName = crmItem.GetValueAsString("first_name"); olItem.LastName = crmItem.GetValueAsString("last_name"); olItem.Email1Address = crmItem.GetValueAsString("email1"); olItem.BusinessTelephoneNumber = crmItem.GetValueAsString("phone_work"); olItem.HomeTelephoneNumber = crmItem.GetValueAsString("phone_home"); olItem.MobileTelephoneNumber = crmItem.GetValueAsString("phone_mobile"); olItem.JobTitle = crmItem.GetValueAsString("title"); olItem.Department = crmItem.GetValueAsString("department"); olItem.BusinessAddressCity = crmItem.GetValueAsString("primary_address_city"); olItem.BusinessAddressCountry = crmItem.GetValueAsString("primary_address_country"); olItem.BusinessAddressPostalCode = crmItem.GetValueAsString("primary_address_postalcode"); olItem.BusinessAddressState = crmItem.GetValueAsString("primary_address_state"); olItem.BusinessAddressStreet = crmItem.GetValueAsString("primary_address_street"); olItem.Body = crmItem.GetValueAsString("description"); if (crmItem.GetValue("account_name") != null) { olItem.Account = crmItem.GetValueAsString("account_name"); olItem.CompanyName = crmItem.GetValueAsString("account_name"); } olItem.BusinessFaxNumber = crmItem.GetValueAsString("phone_fax"); olItem.Title = crmItem.GetValueAsString("salutation"); if (olItem.Sensitivity != Outlook.OlSensitivity.olNormal) { Log.Info($"ContactSyncing.SetOutlookItemPropertiesFromCrmItem: setting sensitivity of contact {crmItem.GetValueAsString("first_name")} {crmItem.GetValueAsString("last_name")} ({crmItem.GetValueAsString("email1")}) to normal"); olItem.Sensitivity = Outlook.OlSensitivity.olNormal; } EnsureSynchronisationPropertiesForOutlookItem( olItem, crmItem.GetValueAsString("date_modified"), crmItem.GetValueAsString("sync_contact"), CrmId.Get(crmItem.id)); } finally { this.SaveItem(olItem); } }
/// <summary> /// Return true if this CRM contact should be synchronised with Outlook. /// </summary> /// <remarks> /// If the 'Sync to Outlook' field is set in CRM, we get 'true' as the value of crmItem.sync_contact. /// But if the field is not set, we do not (or do not reliably) get 'false'. The sync_contact /// property may have a value of ''. /// </remarks> /// <param name="crmItem">The CRM contact.</param> /// <returns>true if this CRM contact should be synchronised with Outlook.</returns> private bool ShouldSyncContact(EntryValue crmItem) { object val = crmItem.GetValue("sync_contact"); return(Boolean.TrueString.ToLower().Equals(val.ToString().ToLower())); }