Hi, I created a basic plugin that generates the account number when creating account, post operation, create. I signed the assembly, and deployed successfully, and I can see the plugin registered in solution as well. But when I created a new account, the account number didn't show up. Please advise what else I missed.
protected override void ExecuteCrmPlugin(LocalPluginContext localContext) { if (localContext == null) { throw new InvalidPluginExecutionException("localContext"); } // Obtain the execution context from the service provider. IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; // 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"]; //</snippetAccountNumberPlugin2> // Verify that the target entity represents an account. // If not, this plug-in was not registered correctly. if (entity.LogicalName == "account") { // An accountnumber attribute should not already exist because // it is system generated. if (entity.Attributes.Contains("accountnumber") == false) { // Create a new accountnumber attribute, set its value, and add // the attribute to the entity's attribute collection. Random rndgen = new Random(); entity.Attributes.Add("accountnumber", rndgen.Next().ToString()); } else { // Throw an error, because account numbers must be system generated. // Throwing an InvalidPluginExecutionException will cause the error message // to be displayed in a dialog of the Web application. throw new InvalidPluginExecutionException("The account number can only be set by the system."); } } } }
*This post is locked for comments