/// <summary> /// Deletes any entity records that were created for this sample. /// <param name="prompt">Indicates whether to prompt the user /// to delete the records created in this sample.</param> /// </summary> public static void DeleteRequiredRecords(CrmServiceClient service, bool prompt) { bool deleteRecords = true; if (prompt) { Console.WriteLine("\nDo you want these entity records deleted? (y/n) [y]: "); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y") || answer == String.Empty); } if (deleteRecords) { service.Delete(Account.EntityLogicalName, accountId); UnpublishDuplicateRuleRequest unpublishRequest = new UnpublishDuplicateRuleRequest { DuplicateRuleId = ruleId }; service.Execute(unpublishRequest); service.Delete(DuplicateRule.EntityLogicalName, ruleId); service.Delete(Account.EntityLogicalName, dupAccountId); Console.WriteLine("Entity records have been deleted."); } }
public void UnpublishDuplicateDetectionRuleBeforeImport(Entity targetEntity) { if (targetEntity.LogicalName.Equals(Constant.DuplicateRule.EntityLogicalName, StringComparison.OrdinalIgnoreCase)) { if (!targetEntity.Contains(Constant.Entity.StatusCode) || (targetEntity.Contains(Constant.Entity.StatusCode) && targetEntity.GetAttributeValue <OptionSetValue>(Constant.Entity.StatusCode).Value == 2)) //"Published" { // unpublish the DuplicateDetection rule before we import (update) var publishReq = new UnpublishDuplicateRuleRequest { DuplicateRuleId = targetEntity.Id }; OrganizationService.Execute(publishReq); // sleep to let the process finish before continuing ;) Thread.Sleep(2000); } } }
/// <summary> /// Deletes any entity records that were created for this sample. /// <param name="prompt">Indicates whether to prompt the user /// to delete the records created in this sample.</param> /// </summary> public void DeleteRequiredRecords(bool prompt) { bool deleteRecords = true; if (prompt) { Console.WriteLine("\nDo you want these entity records deleted? (y/n) [y]: "); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y") || answer == String.Empty); } if (deleteRecords) { _service.Delete(Account.EntityLogicalName, _accountId); UnpublishDuplicateRuleRequest unpublishRequest = new UnpublishDuplicateRuleRequest { DuplicateRuleId = _ruleId }; _service.Execute(unpublishRequest); _service.Delete(DuplicateRule.EntityLogicalName, _ruleId); _service.Delete(Account.EntityLogicalName, _dupAccountId); Console.WriteLine("Entity records have been deleted."); } }