private void DeleteAttribute() { var entityname = ((EntityMetadataProxy)cmbEntities.SelectedItem).Metadata.LogicalName; var attributename = lblPrefix.Text + txtLogicalName.Text; var req = new DeleteAttributeRequest { EntityLogicalName = entityname, LogicalName = attributename }; WorkAsync(new WorkAsyncInfo("Deleting attribute...", (eventargs) => { LogUse("Delete"); Service.Execute(req); }) { PostWorkCallBack = (completedargs) => { if (completedargs.Error != null) { MessageBox.Show($"Delete attribute failed:\n{completedargs.Error}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Attribute deleted!"); } UpdateUI(ForceLoadAttributes); } }); }
/// <summary> /// Deletes/Reverts the record that was created/changed 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 and attribute to be deleted? (y/n)"); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y")); } if (deleteRecords) { //Delete all records and attributes created for this sample. _serviceProxy.Delete(Account.EntityLogicalName, _account1ID); _serviceProxy.Delete(Account.EntityLogicalName, _account2ID); DeleteAttributeRequest deleteAttribute = new DeleteAttributeRequest { EntityLogicalName = Account.EntityLogicalName, LogicalName = dtAttribute.SchemaName.ToLower() }; _serviceProxy.Execute(deleteAttribute); Console.WriteLine("Deleted all records and attribute created for this sample."); } }
/// <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)"); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y")); } if (deleteRecords) { DeleteAttributeRequest deleteAttributeRequest = new DeleteAttributeRequest { EntityLogicalName = Contact.EntityLogicalName, LogicalName = _picklistName }; _serviceProxy.Execute(deleteAttributeRequest); _serviceProxy.Delete(Solution.EntityLogicalName, _primarySolutionId); _serviceProxy.Delete(Solution.EntityLogicalName, _secondarySolutionId); _serviceProxy.Delete(Publisher.EntityLogicalName, _publisherId); Console.WriteLine("Entity records have been deleted."); } }
/// <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 to be deleted? (y/n)"); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y")); } if (deleteRecords) { DeleteAttributeRequest delSeriesAttribute = new DeleteAttributeRequest { LogicalName = "new_customappseriesattribute", EntityLogicalName = RecurringAppointmentMaster.EntityLogicalName }; _serviceProxy.Execute(delSeriesAttribute); DeleteAttributeRequest delInstanceAttribute = new DeleteAttributeRequest { LogicalName = "new_customappinstanceattribute", EntityLogicalName = Appointment.EntityLogicalName }; _serviceProxy.Execute(delInstanceAttribute); // Publish all the changes to the solution. PublishAllXmlRequest delRequest = new PublishAllXmlRequest(); _serviceProxy.Execute(delRequest); Console.WriteLine("Entity records have been deleted."); } }
public void Execute(IServiceProvider serviceProvider) { ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); var ent = (Entity)context.InputParameters["Target"]; string entity = ent.Contains("ita_entity") ? (string)ent["ita_entity"] : null; string attribute = ent.Contains("ita_attribute") ? (string)ent["ita_attribute"] : null; if (entity != null && attribute != null) { IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { DeleteAttributeRequest dar = new DeleteAttributeRequest(); dar.EntityLogicalName = entity; dar.LogicalName = attribute; service.Execute(dar); ent["statuscode"] = new OptionSetValue(455000000); } catch (Exception ex) { ent["ita_details"] = ex.Message; ent["statuscode"] = new OptionSetValue(455000001); } } }
protected override void ProcessRecord() { base.ProcessRecord(); if (!ConfirmDelete("OCIDatacatalogAttribute", "Remove")) { return; } DeleteAttributeRequest request; try { request = new DeleteAttributeRequest { CatalogId = CatalogId, DataAssetKey = DataAssetKey, EntityKey = EntityKey, AttributeKey = AttributeKey, IfMatch = IfMatch, OpcRequestId = OpcRequestId }; response = client.DeleteAttribute(request).GetAwaiter().GetResult(); WriteOutput(response); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
public void DeleteAttribute(IOrganizationService service) { var request = new DeleteAttributeRequest { EntityLogicalName = Entity, LogicalName = LogicalName }; service.Execute(request); }
public void DeleteAttribute(string logicalname) { var request = new DeleteAttributeRequest { EntityLogicalName = entity, LogicalName = logicalname }; service.Execute(request); }
/// <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 toBeDeleted = true; if (prompt) { // Ask the user if the created entities should be deleted. Console.Write("\nDo you want these entity records deleted? (y/n) [y]: "); String answer = Console.ReadLine(); if (answer.StartsWith("y") || answer.StartsWith("Y") || answer == String.Empty) { toBeDeleted = true; } else { toBeDeleted = false; } } if (toBeDeleted) { // Delete all records created in this sample. // Delete the secured custom field #1. DeleteAttributeRequest deleteRequest = new DeleteAttributeRequest() { EntityLogicalName = Account.EntityLogicalName, LogicalName = "secret_phone", RequestId = _secretPhoneId }; _serviceProxy.Execute(deleteRequest); // Delete the secured custom field #2. deleteRequest = new DeleteAttributeRequest() { EntityLogicalName = Account.EntityLogicalName, LogicalName = "secret_home", RequestId = _secretHomeId }; _serviceProxy.Execute(deleteRequest); // Delete the account record. _serviceProxy.Delete(Account.EntityLogicalName, _accountRecordId); // We don't need to delete POAA records, because // they were deleted when we deleted the account record. Console.WriteLine("Entity record(s) have been deleted."); } }
/// <summary> /// Deletes/Reverts the record that was created/changed 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 to be deleted? (y/n)"); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y")); } if (deleteRecords) { #region How to delete attribute //<snippetWorkWithAttributes9> // Delete all attributes created for this sample. foreach (AttributeMetadata anAttribute in addedAttributes) { // Create the request object DeleteAttributeRequest deleteAttribute = new DeleteAttributeRequest { // Set the request properties EntityLogicalName = Contact.EntityLogicalName, LogicalName = anAttribute.SchemaName }; // Execute the request _serviceProxy.Execute(deleteAttribute); } //</snippetWorkWithAttributes9> #endregion How to delete attribute #region How to remove inserted status value //<snippetWorkWithAttributes10> // Delete the newly inserted status value. // Create the request object DeleteOptionValueRequest deleteRequest = new DeleteOptionValueRequest { AttributeLogicalName = "statuscode", EntityLogicalName = Contact.EntityLogicalName, Value = _insertedStatusValue }; // Execute the request _serviceProxy.Execute(deleteRequest); Console.WriteLine("Deleted all attributes created for this sample."); //</snippetWorkWithAttributes10> #endregion How to remove inserted status value #region Revert the changed state value //<snippetWorkWithAttributes11> // Revert the state value label from Open to Active. // Create the request. UpdateStateValueRequest revertStateValue = new UpdateStateValueRequest { AttributeLogicalName = "statecode", EntityLogicalName = Contact.EntityLogicalName, Value = 1, Label = new Label("Active", _languageCode) }; // Execute the request. _serviceProxy.Execute(revertStateValue); // NOTE: All customizations must be published before they can be used. _serviceProxy.Execute(new PublishAllXmlRequest()); Console.WriteLine( "Reverted {0} state attribute of {1} entity from 'Open' to '{2}'.", revertStateValue.AttributeLogicalName, revertStateValue.EntityLogicalName, revertStateValue.Label.LocalizedLabels[0].Label ); //</snippetWorkWithAttributes11> #endregion Revert the changed state value } }
public void DeleteField(string fieldName, string entityName) { if (FieldExists(fieldName, entityName)) { var request = new DeleteAttributeRequest { EntityLogicalName = entityName, LogicalName = fieldName }; Execute(request); } }
/// <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)"); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y")); } if (deleteRecords) { #region How to delete a option from a option set // Use the DeleteOptionValueRequest message // to remove the newly inserted label. DeleteOptionValueRequest deleteOptionValueRequest = new DeleteOptionValueRequest { OptionSetName = _globalOptionSetName, Value = _insertedOptionValue }; // Execute the request. _serviceProxy.Execute(deleteOptionValueRequest); Console.WriteLine("Option Set option removed."); #endregion How to delete a option from a option set #region How to delete attribute // Create the request to see which components have a dependency on the // global option set. RetrieveDependentComponentsRequest dependencyRequest = new RetrieveDependentComponentsRequest { ObjectId = _optionSetId, ComponentType = (int)componenttype.OptionSet }; RetrieveDependentComponentsResponse dependencyResponse = (RetrieveDependentComponentsResponse)_serviceProxy.Execute( dependencyRequest); // Here you would check the dependencyResponse.EntityCollection property // and act as appropriate. However, we know there is exactly one // dependency so this example deals with it directly and deletes // the previously created attribute. DeleteAttributeRequest deleteAttributeRequest = new DeleteAttributeRequest { EntityLogicalName = Contact.EntityLogicalName, LogicalName = "sample_examplepicklist" }; _serviceProxy.Execute(deleteAttributeRequest); Console.WriteLine("Referring attribute deleted."); #endregion How to delete attribute #region How to delete global option set // Finally, delete the global option set. Attempting this before deleting // the picklist above will result in an exception being thrown. DeleteOptionSetRequest deleteRequest = new DeleteOptionSetRequest { Name = _globalOptionSetName }; _serviceProxy.Execute(deleteRequest); Console.WriteLine("Global Option Set deleted"); #endregion How to delete global option set } }
public override void DoAction(BaseSolution solution) { ActionStarted(); DynamicsSolution ds = (DynamicsSolution)solution; ds.Service.PublishAll(); XmlDocument doc = new XmlDocument(); doc.LoadXml(XML); var actions = doc.GetElementsByTagName("action"); foreach (XmlNode a in actions) { try { switch (a.Attributes["target"].Value) { case "attribute": DeleteAttributeRequest dar = new DeleteAttributeRequest(); dar.EntityLogicalName = a.Attributes["entity"].Value; dar.LogicalName = a.Attributes["attribute"].Value; ds.Service.Service.Execute(dar); break; case "entity": DeleteEntityRequest der = new DeleteEntityRequest(); der.LogicalName = a.Attributes["entity"].Value; ds.Service.Service.Execute(der); break; case "pluginstep": break; case "plugin": break; case "businessrule": case "workflow": try { SetStateRequest deactivateRequest = new SetStateRequest { EntityMoniker = new EntityReference("workflow", Guid.Parse(a.Attributes["recordid"].Value)), State = new OptionSetValue(0), Status = new OptionSetValue(1) }; ds.Service.Service.Execute(deactivateRequest); ds.Service.Service.Delete("workflow", Guid.Parse(a.Attributes["recordid"].Value)); } catch (Exception ex) { if (!ex.Message.ToUpper().Contains(a.Attributes["recordid"].Value.ToUpper())) { throw; } //Ignore if the ID is there - likely "does not exist" error //May need an extra attribute to decide if to ignore or not } break; case "webresource": ds.Service.Service.Delete("webresrouce", Guid.Parse(a.Attributes["recordid"].Value)); break; case "record": ds.Service.Service.Delete(a.Attributes["entity"].Value, Guid.Parse(a.Attributes["recordid"].Value)); break; case "globaloptionset": ds.Service.Service.Execute(new DeleteOptionSetRequest { Name = a.Attributes["name"].Value }); break; case "globaloptionsetvalue": ds.Service.Service.Execute(new DeleteOptionValueRequest { OptionSetName = a.Attributes["name"].Value, Value = int.Parse(a.Attributes["value"].Value) }); break; case "optionsetvalue": ds.Service.Service.Execute(new DeleteOptionValueRequest { EntityLogicalName = a.Attributes["entity"].Value, AttributeLogicalName = a.Attributes["attribute"].Value, Value = int.Parse(a.Attributes["value"].Value) }); break; } } catch (Exception ex) { if (ex.Message.ToLower().Contains("could not find") || ex.Message.ToLower().Contains("does not exist")) { if (a.Attributes["errorIfMissing"] == null || a.Attributes["errorIfMissing"].Value == "true") { throw; } } else { throw; } } } ActionCompleted(); }
/// <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)"); String answer = Console.ReadLine(); deleteRecords = (answer.StartsWith("y") || answer.StartsWith("Y")); } if (deleteRecords) { #region How to delete a option from a option set //<snippetWorkwithGlobalOptionSets11> // Use the DeleteOptionValueRequest message // to remove the newly inserted label. DeleteOptionValueRequest deleteOptionValueRequest = new DeleteOptionValueRequest { OptionSetName = _globalOptionSetName, Value = _insertedOptionValue }; // Execute the request. _serviceProxy.Execute(deleteOptionValueRequest); //</snippetWorkwithGlobalOptionSets11> Console.WriteLine("Option Set option removed."); #endregion How to delete a option from a option set #region How to delete attribute //<snippetWorkwithGlobalOptionSets12> // Create the request to see which components have a dependency on the // global option set. RetrieveDependentComponentsRequest dependencyRequest = new RetrieveDependentComponentsRequest { ObjectId = _optionSetId, ComponentType = (int)componenttype.OptionSet }; RetrieveDependentComponentsResponse dependencyResponse = (RetrieveDependentComponentsResponse)_serviceProxy.Execute( dependencyRequest); // Here you would check the dependencyResponse.EntityCollection property // and act as appropriate. However, we know there is exactly one // dependency so this example deals with it directly and deletes // the previously created attribute. DeleteAttributeRequest deleteAttributeRequest = new DeleteAttributeRequest { EntityLogicalName = Contact.EntityLogicalName, LogicalName = "sample_examplepicklist" }; _serviceProxy.Execute(deleteAttributeRequest); Console.WriteLine("Referring attribute deleted."); #endregion How to delete attribute #region How to delete global option set // Finally, delete the global option set. Attempting this before deleting // the picklist above will result in an exception being thrown. //<snippetWorkwithGlobalOptionSets.DeleteOptionSetRequest> DeleteOptionSetRequest deleteRequest = new DeleteOptionSetRequest { Name = _globalOptionSetName }; _serviceProxy.Execute(deleteRequest); //</snippetWorkwithGlobalOptionSets.DeleteOptionSetRequest> //</snippetWorkwithGlobalOptionSets12> Console.WriteLine("Global Option Set deleted"); #endregion How to delete global option set } }
static void Main(string[] args) { try { DeleteData fred = new DeleteData(); /* //This section is used to construct the xml file that will ultimately serve up the data fred.entityName = "myEntity"; fred.fieldList = new string[] { "First", "Second" }; XmlSerializer x = new XmlSerializer(typeof(DeleteData)); using (TextWriter myWriter = new StreamWriter("myData.xml")) { x.Serialize(myWriter, fred); } return; */ //Set up the connections based upon the command line data if (args.Length < 2) { Console.WriteLine("Nah. Need a url and tenant for the target system\ne.g. sumfing like http://crmdev11 EnterpriseInns"); } if (File.Exists(outputFile)) File.Delete(outputFile); writeLog("System initialised."); writeLog("Target URL: " + args[0]); writeLog("Tenant: " + args[1]); IOrganizationService aService = GetOrganisationService(args[1], args[0]); DeleteData deleteData; XmlSerializer dx = new XmlSerializer(typeof(DeleteData)); using (TextReader myReader = new StreamReader(fileName)) { deleteData = (DeleteData)dx.Deserialize(myReader); } DeleteAttributeRequest dar = new DeleteAttributeRequest(); dar.EntityLogicalName = deleteData.entityName; DeleteAttributeResponse delResponse; foreach (string attr in deleteData.fieldList) { writeLog(""); writeLog("Deleting " + attr); dar.LogicalName = attr; try { delResponse = (DeleteAttributeResponse)aService.Execute(dar); writeLog("Delete successful"); } catch (System.ServiceModel.FaultException ssf) { writeLog(ssf.Message); } } } catch (Exception e) { Console.WriteLine(e.Message); } }