Quantcast
Channel: CRM Development 論壇
Viewing all articles
Browse latest Browse all 10280

Generic Error with MS CRM Plugin

$
0
0

I am trying to run a sample plugin for MS CRM, but I am continuously getting a generic error:

An error occurred. Contact a system administrator or refer to the Microsoft Dynamics CRM SDK troubleshooting guide.

This is an example code, and I have verified that all the entities and fields which are utilized by this plugin are defined and are at there places. but I am continuously getting this Business Error:

public void Execute(IServiceProvider serviceProvider)
        {

            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
            serviceProvider.GetService(typeof(IPluginExecutionContext));


            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("account") &&
            context.InputParameters["account"] is Entity)
            {
                // Obtain the target entity from the input parmameters.
                Entity entity = (Entity)context.InputParameters["account"];



                try
                {
                    //check if the account number exist

                    if (entity.Attributes.Contains("account number") == false)
                    {

                        //create a task
                        Entity task = new Entity("task");
                        task["subject"] = "Account number is missing";
                        task["regardingobjectid"] = new EntityReference("account", new Guid(context.OutputParameters["id"].ToString()));

                        //adding attribute using the add function
                        // task["description"] = "Account number is missng for the following account. Please enter the account number";
                        task.Attributes.Add("description", "Account number is missng for the following account. Please enter the account number");



                        // Obtain the organization service reference.
                        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


                        // Create the task in Microsoft Dynamics CRM.
                        service.Create(task);


                    }
                }

                catch (FaultException ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
                }

            }

        }
    }//end class


Viewing all articles
Browse latest Browse all 10280


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>