MS CRM Plugin debugging

top-debugging-tips

To debug plugin, we have two ways, One is explained in below provided link, I will explain the other.

https://support.microsoft.com/en-us/kb/2778280

debugging plugin in above provided way is good but still its not that handy, and we need exception for that . But don’t we have any other way fro this?..   Yes, we have .. we can create console application and from that console application we can check our code and this console application will be useful to check workflow as well,

to create this kind of console we need following reference to be added in the application

ref

Now, prepare config file with proper CRM URL and credentials etc … ref below screen

config

Now, its time to create CRM helper class, that will help you to connect MS CRM, you will get sample of it on MSDN itself, for ref. here is the one, following class has been written with singleton pattern, thus it will not create another object of same thing, on second call it will return earlier created object, i used it one of my third application

namespace TestConsole.CRMConn
{
 /// <summary>
 /// Singleton class
 /// </summary>
 public class CRMConnection
 {
 /// <summary>
 /// providing Crm Connection - Create one time instance
 /// </summary>
 private static CRMConnection _serviceInstance;
 /// <summary>
 /// CRM Service Interface
 /// </summary>
 public static IOrganizationService _organizationService;
 /// <summary>
 /// Control Id - CRM Sdk
 /// </summary>
 private Guid _controlID;
 /// <summary>
 /// Not Yet use in Application - For Future Scope while we would like to work or in a case of multithreading(Sigleton is no more available).
 /// </summary>
 private static object _mutexLock = new object();

 /// <summary>
 /// OrganizationService
 /// </summary>
 public IOrganizationService OrganizationService
 {
 get { return _organizationService; }
 }

 /// <summary>
 /// ControlID
 /// </summary>
 public Guid ControlID
 {
 get { return _controlID; }
 }

 /// <summary>
 /// CRMConnection - Private connection for Singleton
 /// works for early and late bound
 /// </summary>
 /// <param name="controlID"></param>
 private CRMConnection(Guid controlID)
 { 
 IServiceConfiguration<IOrganizationService> serviceConfig = null;
 OrganizationServiceProxy service = null;
 ClientCredentials userCredentials = null;

 serviceConfig = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(
 new Uri(ConfigurationManager.AppSettings["CrmUrl"] + "/XRMServices/2011/Organization.svc"));

 userCredentials = new ClientCredentials();
 userCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

 using (service = new OrganizationServiceProxy(serviceConfig, userCredentials))
 {
 service.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
 }

 _organizationService = (IOrganizationService)service;
 _controlID = controlID;

 } 

 /// <summary>
 /// Return Crm Connection Object
 /// </summary>
 /// <returns></returns>
 public static CRMConnection GetConnection()
 {
 if (_serviceInstance == null)
 {
 lock (_mutexLock) //in case of multi threading
 _serviceInstance = new CRMConnection(new Guid());//guid in case of creation of uniq instance.
 
 }
 return _serviceInstance;
 } 
 }
}

now, write normal plugin / workflow, and change the Context with hard coded record ID, just like shown below,

class

Now, it will behave just like an normal dot net application, you have complete control over it. 🙂

Hope it help some one..

 

Thanks.

Advertisements

One thought on “MS CRM Plugin debugging

  1. Pingback: Plugin debugging | CRM Practice

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s