Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

Regarding update plugin

$
0
0

I have s very simple plugin  registered on pre operation stage at update message having execution mode as Sysnchronous. Ia m getting exception as An error occurred in the plguin.

Can anyone help me here to know where I am going wrong.

 public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory _serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService _orgService = _serviceFactory.CreateOrganizationService(context.UserId);

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                Entity entity = (Entity)context.InputParameters["Target"];
                if (entity.LogicalName == "account")
                {
                    string notes = "test";
                    try
                    {
                       
                        if (entity.Attributes.Contains("numberofemployees"))
                        {
                            
                            entity.attributes["description"] = notes;
                            
                        }
                       
                    }
                    catch (FaultException ex)
                    {
                        throw new InvalidPluginExecutionException("An error occured in plugin:",ex);
                    }
                }
            }


Viewing all articles
Browse latest Browse all 55831

Trending Articles



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