/// <summary> /// Delete all remaining entity records that were created by this sample. /// <param name="prompt">When true, the user is prompted whether /// the records created in this sample should be deleted; otherwise, false.</param> /// </summary> public void DeleteEntityRecords(OrganizationServiceProxy service, EntityReferenceCollection records, 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) { while (records.Count > 0) { EntityReference entityRef = records[records.Count - 1]; Console.WriteLine("Deleting {0} '{1}' ...", entityRef.LogicalName, entityRef.Name); service.Delete(entityRef.LogicalName, entityRef.Id); records.Remove(entityRef); } Console.WriteLine("Entity records have been deleted."); } }
protected override void ExecuteCrmPlugin(LocalPluginContext localContext) { var context = localContext.PluginExecutionContext; EntityReference targetEntity = null; ppp_Traveller traveller = null; string relationshipName = string.Empty; EntityReferenceCollection relatedEntities = null; if (context.MessageName != "Associate") { return; } // Get the "Relationship" Key from context if (context.InputParameters.Contains("Relationship")) { relationshipName = context.InputParameters["Relationship"].ToString(); } // Check the "Relationship Name" with your intended one if (relationshipName != "ovs_ppp_Traveller_FlightConn_Facility.Referenced") { return; } // Get Entity 1 reference from "Target" Key from context if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) { targetEntity = (EntityReference)context.InputParameters["Target"]; traveller = GetTraveler(localContext, targetEntity.Id); } // Get Entity 2 reference from " RelatedEntities" Key from context if (context.InputParameters.Contains("RelatedEntities") && context.InputParameters["RelatedEntities"] is EntityReferenceCollection) { relatedEntities = context.InputParameters["RelatedEntities"] as EntityReferenceCollection; foreach (var flightConnection in relatedEntities) { if (flightConnection.Id == traveller.ppp_FlightOrigin.Id || flightConnection.Id == traveller.ppp_FlightDestination.Id) { relatedEntities.Remove(flightConnection); throw new InvalidPluginExecutionException("Fight connection cannot be the same as the flight origin or flight desitination"); } } } }
/// <summary> /// Delete all remaining entity records that were created by this sample. /// <param name="prompt">When true, the user is prompted whether /// the records created in this sample should be deleted; otherwise, false.</param> /// </summary> public void DeleteEntityRecords(OrganizationServiceProxy service, EntityReferenceCollection records, 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) { while (records.Count > 0) { EntityReference entityRef = records[records.Count - 1]; Console.WriteLine("Deleting {0} '{1}' ...", entityRef.LogicalName, entityRef.Name); service.Delete(entityRef.LogicalName, entityRef.Id); records.Remove(entityRef); } Console.WriteLine("Entity records have been deleted."); } }