5 syntax changes in Dynamics CRM 2011 plugins

Source

There are number of changes between Dynamics CRM 2011 SDK and CRM 4 SDK. Let’s take a look at what has changed between plugins.

1. The IPlugin now resides in Microsoft.Xrm.Sdk namespace instead of Microsoft.Crm.Sdk
public class ClassName : Microsoft.Crm.Sdk.IPlugin
public class ClassName : Microsoft.Xrm.Sdk.IPlugin

2. The Execute method signature of the IPlugin interface has changed, it now expects an IServiceProvider instead of the IPluginExecutionContext.
public void Execute(IPluginExecutionContext context)
public void Execute(IServiceProvider serviceProvider)
3. 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));
4. ICrmService has been changed to IOrganizationService.
ICrmService sdk = context.CreateCrmService(true);
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService sdk = factory.CreateOrganizationService(context.UserId);
5. DynamicEntity has been changed to Entity.
· Properties property of DynamicEntity no longer exists
· Getting and Setting values no longer use *Property classes,
eg: no more KeyProperty, StringProperty…etc, simply do int value = (int)entity[“schema_name”];
if (context.InputParameters.Properties.Contains(“Target”) && context.InputParameters.Properties[“Target”is DynamicEntity) if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”is Entity

2) Additionally (Spanish)-
Farewell to “DynamicEntity” in CRM 2011
Microsoft has begun to “drop” a lot of information related to the new CRM 2011.
Within this information issued a beta version of the forthcoming SDK, which makes some ideas of where the XRM point shots.
The SDK can be downloaded from here: http://go.microsoft.com/fwlink/?LinkID=200082&clcid=0x409 .
Gradually try to be publishing the news and changes to be found therein.
One of the most interesting points is related to the “death” in class “DynamicEntity” that we use to work with the SDK.
From now, referred to as “Entity”, which is the class that will replace the above “DynamicEntity.”
This will cause some advantages as it will be much more comfortable working with all entities.
The Entity class is put into “Microsoft.Xrm.Sdk.”
Here are some examples of the changes:
//CRM 2011
Entity entity = new Entity(Account.EntityLogicalName);
entity[“accountid”] = Guid.NewGuid();

// CRM 4.0
DynamicEntity entity = new DynamicEntity();
entity.Name = EntityName.account.ToString();
entity[“accountid”] = new Key(Guid.NewGuid());

3)  Also…

SDK changes I’ve noticed while porting this from CRM 4.0 to CRM 2011

• Enumeration classes like Microsoft.Crm.Sdk.MessageName, ParameterName are not available
• IPluginExecutionContext.Depth is equal to 2 when the plugin is executed in the Update message
• CrmMoney is now Money, was expecting decimal since most other CRM data types are native .net types
• To get all the columns use new ColumnSet(true) instead of new AllColumns()
• Input/OutputParameters of IPluginExecutionContext is now typeof ParameterCollection instead of PropertyBag

 

Advertisements

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

%d bloggers like this: