Hi Coline, I would suggest you to use ITracingService to debug your code. So when your plug-in throw error you will get proper error message. also you can put debugging steps within your plug-in. After seeing your code I would like to know what is the data type of "new_estnoofhours" attribute? PFA below small code snippet of working example of plug-in. I think it would help. In below code We are reading config entity and generate new number. Assign new number to account entity Update new number to config entity again so next time when plug-in execute it generate unique number based on last update number. // Obtain the execution context from the service provider. IPluginExecutionContext context = localContext.PluginExecutionContext; // The InputParameters collection contains all the data passed in the message request. if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Obtain the target entity from the input parameters. Entity entity = (Entity)context.InputParameters["Target"]; // Check of target entity is not Certificates then Return from further execution if (entity.LogicalName != "account") return; // Obtain Organization Service Reference from ServiceFactory IOrganizationService service = localContext.OrganizationService; ITracingService trSer = localContext.TracingService; // Create a OrganizationServiceContext OrganizationServiceContext orgContext = new OrganizationServiceContext(service); // Setting the Merge Option orgContext.MergeOption = MergeOption.NoTracking; try { var CertAutoNumberRecord = (from certAutoNum in orgContext.CreateQuery("new_cert_autonumber") where certAutoNum.GetAttributeValue ("new_name").Equals(entity.LogicalName) select new CRM.Package.POC.Plugins.Model.CertAutoNumber() { CertAutoNumberId = certAutoNum.GetAttributeValue ("new_cert_autonumberid"), CertPrefix = certAutoNum.GetAttributeValue ("new_cert_prefix"), CertNumber = certAutoNum.GetAttributeValue ("new_cert_number") }).FirstOrDefault(); // If CertAutoNumberRecord is retrieved if (CertAutoNumberRecord != null) { int NewCertNumber; int NewPrefix; string NewCertificateId; // Check if Existing Value is Int type if (Int32.TryParse(CertAutoNumberRecord.CertNumber, out NewCertNumber)) { // Increment the Number by 1 NewCertNumber = NewCertNumber + 1; } else throw new Exception("Cert. Number configured in configuration entity (new_cert_autonumber) is not an Integer."); // Check if Existing Value is Int type if (Int32.TryParse(CertAutoNumberRecord.CertPrefix, out NewPrefix)) { // If Prefix is also and Integer Type along with Cert Number. Generate a new CertificateId NewCertificateId = NewPrefix.ToString() + NewCertNumber.ToString(); } else throw new Exception("Cert. Number configured in configuration entity (new_cert_autonumber) is not an Integer."); entity.Attributes.Add("new_accountid", NewCertificateId); // Update NewCertNumber to Certificate Auto Number Record ColumnSet CertNumberAttribute = new ColumnSet(new string[] { "new_cert_number" }); // Retrieve CertAutoNumber Record Entity AutoNumberConfigRecord = service.Retrieve("new_cert_autonumber", CertAutoNumberRecord.CertAutoNumberId, CertNumberAttribute); // Assign new number to CertNumber field. AutoNumberConfigRecord.Attributes["new_cert_number"] = Convert.ToString(NewCertNumber); // Update Record service.Update(AutoNumberConfigRecord); //} If its help please mark my post as Answer appreciate your support.
↧