Plugin to check the InputParameters value of the Context in CRM 2011.


Wrote a simple plugin to check the value of InputParameters being passed on update of lead record.

  public void Execute(IServiceProvider serviceProvider)
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            Entity myEntity = (Entity)context.InputParameters["Target"];
            // Get the attribute collection
            AttributeCollection myAttColl = myEntity.Attributes;
            // Write in a log file
            TextWriter log = TextWriter.Synchronized(File.AppendText(@"C:\InputParameterLog.txt"));

            log.WriteLine("Log generated at  " + DateTime.Now);

            foreach (KeyValuePair<string, object> myKV in myAttColl)
                log.WriteLine("Key - " + myKV.Key);

                if (myKV.Value == null)
                    log.WriteLine("Value - null");
                else if (myKV.Value.GetType()== typeof(EntityReference))
                    EntityReference eRef = myKV.Value as EntityReference;
                    log.WriteLine("Id - " + eRef.Id.ToString());
                    log.WriteLine("Logical Name - " + eRef.LogicalName);
                    log.WriteLine("Name - " + eRef.Name);

                else if (myKV.Value.GetType() == typeof(OptionSetValue))
                    OptionSetValue oSetValue = myKV.Value as OptionSetValue;
                    log.WriteLine("OptionSetValue - " + oSetValue.Value);

                    log.WriteLine("Value - " + myKV.Value.ToString());



Haven’t tested it though, might be useful while debugging.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

One thought on “Plugin to check the InputParameters value of the Context in CRM 2011.”

Share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.