Tuesday, January 3, 2012

Writing a Basic Plug-in in MS CRM 2011

using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;

namespace Microsoft.Crm.Sdk.Samples
{
    public class SamplePlugin: IPlugin
    {
// Basic Constructor with out any parameters
public SamplePlugin(){
// do logic
}
// Basic Constructor with one parameters,the 1st parameter is the unsecure value
public SamplePlugin(string unsecure){
// do logic
}
// Basic Constructor with one parameters,the 1st parameter is the unsecure value and the 2nd is the secure
public SamplePlugin(string unsecure, string secure){
// do logic
}

        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context =
                (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // Get a reference to the organization service.
            IOrganizationServiceFactory factory =
                (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = factory.CreateOrganizationService(context.UserId);

            // Get a reference to the tracing service.
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            try
            {
                // Plug-in business logic goes below this line.
                // Invoke organization service methods.
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                // Handle the exception.
            }
        }
    }
}

1 comment:

  1. your blog post has been copied
    http://srikanthcrm.wordpress.com/2012/02/14/writing-a-basic-plug-in-in-ms-crm-2011/

    ReplyDelete