Saturday 27 December 2014

Microsoft Dynamics CRM 4.0 to 2011/2013 Plugins Migration

Below table consists of major code change while migrating plugins from CRM 4.0 to CRM 2011/CRM2013.

Data type
Description
Microsoft Dynamics CRM 4.0 version
Microsoft Dynamics CRM  2011/2013 version
Dynamic Entity
DynamicEntity has been changed to Entity
   
    

if (context.InputParameters.Properties.Contains("Target") &&     context.InputParameters.Properties["Target"] is DynamicEntity)
if (context.InputParameters.Contains("Target") &&
    context.InputParameters["Target"] is Entity)
CrmService
ICrmService has been changed to IOrganizationService
ICrmService sdk = context.CreateCrmService(true);
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService sdk = factory.CreateOrganizationService(context.UserId);
Lookup
Lookup classes change to EntityReference
Lookup entity = (Lookup) context.InputParameters.Properties["Target"];
Microsoft.Xrm.Sdk.EntityReference entity = (EntityReference) context.InputParameters["Target"];
Moniker
Moniker classes change to EntityReference
Moniker entity = (Moniker) context.InputParameters.Properties["Target"];
Microsoft.Xrm.Sdk.EntityReference entity = (EntityReference) context.InputParameters["Target"];
GetProperties / PropertyAccess
Properties property of DynamicEntity no longer exists.
Getting and Setting values no longer use Property classes.

if (context.InputParameters.Properties.Contains("Target") &&     context.InputParameters.Properties["Target"] is DynamicEntity)
if (context.InputParameters.Contains("Target") &&
    context.InputParameters["Target"] is Entity)
BusinessEntityCollection
BusinessEntityCollection has been changed to Entity]


Picklist
Picklist in CRM 4.0 has been changed to OptionSetValue in CRM 2011
Var pick =  new Picklist(1);
Var options = new OptionSetValue(1);
Key
Key is no longer a separate thing in CRM 2011, it’s just a System.Guid
Var key = new Key(“<value>”);
Var key = new System.Guid(“<value>”);
SoapException
SoapException has been changed to FaultException in CRM 2011
Catch(SoapException ex){
}
catch (FaultException<OrganizationServiceFault> ex){
        // Handle the exception.
            }

CrmSdk
Namespace change from Microsoft.Crm.Sdk to Microsoft.Xrm.Sdk
public class ClassName : Microsoft.Crm.Sdk.IPlugin
public class ClassName : Microsoft.Xrm.Sdk.IPlugin
IPluginExecutionContext
IPluginExecutionContext change
public void Execute(IPluginExecutionContext context)
public void Execute(IServiceProvider serviceProvider)
IPluginExecutionContext
To get a reference to the IPluginExecutionContext you now need to call the GetService method of the IServiceProvider interface.
public void Execute(IPluginExecutionContext context)
Microsoft.Xrm.Sdk.IPluginExecutionContext context =(Microsoft.Xrm.Sdk.IPluginExecutionContext)
    serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)
Customer/Owner
Customer/Owner changed to Lookup


CrmDateTime -> Datetime

CrmBoolean-> Boolean

CrmDecimal->Decimal

CrmNumber->Integer
Crm types change to generic types
attributeValue = ((Microsoft.Crm.Sdk.CrmBoolean)propertyCollection[attribute]).Value.ToString();
attributeValue = ((bool)propertyCollection[attribute]).Value.ToString();




Hope this helps,
Yusuf

No comments:

Post a Comment