Service Provider in Plugins explained

When a particular event occurs in Microsoft Dynamics CRM, such as “create of a contact” or “update of an account”, the Execute method is invoked for any plugins registered on the event. This method includes a single serviceProvider parameter which provides useful service information about the execution of the plugin. In this post, we will take a look at the information that is made available by the serviceProvider parameter.

The types of service objects available include the following:

• IPluginExecutionContext
• IOrganizationServiceFactory
• ITracingService

The IPluginExecutionContext service object is the most useful of the three and provides contextual information to the plugin at run-time. It includes details about the user who triggered the plugin event as well as transactional information handled at the platform layer. The following code can be used to obtain the execution context from the service provider:

IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

The IOrganizationServiceFactory service object allows us to create an instance of the organization service which can be used to define and execute various platform requests. The following code can be used to achieve this:

IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService sdk = factory.CreateOrganizationService(context.UserId);

In the example above, we pass in the GUID of the user who triggered the plugin event, which is obtained from the IPluginExecutionContext. Alternatively, we can pass in the GUID of another CRM user, or pass in a null value to execute the plugin logic under the system context.

Lastly, the ITracingService allows us to trace the plugin execution flow and any variables for debugging purposes.

There you have it, an introduction to the various service objects that we will be working with in our journey to create plugins for Microsoft Dynamics CRM. In my next post, we will take a closer look at the IPluginExecutionContext.

Cheers,

PMDY

Two major functionalities going to be deprecated from future releases of Dynamics CRM..

As a part of important changes coming in the future releases of Dynamics CRM, two major existing functionalities which had been in place from CRM 2015 version would be deprecated and find their details as below.

  1. Removal of legacy form rendering option
     With Microsoft Dynamics CRM Online 2015 Update 1, introduced a new form rendering engine (sometimes called “turbo forms” ) that provides improved performance. This new rendering engine became available for customers with on-premises deployments with Microsoft Dynamics CRM 2016.

Because such a change can introduce different behaviors in form scripts, CRM 2016  currently provide a Use legacy form rendering option in System Settings so that an organization can opt out if they detect problems. This is intended to be a temporary solution. We hope these kind of issues would be addressed soon.

The Use legacy form rendering option will be removed in the next major release. Legacy form rendering (sometimes called “refresh forms”) is deprecated and will no longer be available. Only the rendering option will be removed; the form definition is still supported. Organizations who have not yet resolved issues with their customizations by using the new form rendering engine should take action immediately so that they will be able to upgrade to the next major version.

If you have turned on legacy form rendering, please turn it off and test your scripts. During testing, if you see breaking changes in forms that use:

  • The supported client API objects and methods documented in MSDN: Client-side programming reference, report this to CRM technical support.
  • Unsupported form objects or methods, remove these customizations or find a different way to achieve the results you want.

So Organizations be aware of this..

2.Microsoft Dynamics Email Router is deprecated

 The Microsoft Dynamics CRM Email Router will become deprecated in the next major release of Microsoft Dynamics CRM. To prepare for this change, we strongly recommend that you migrate all email routing functionality to use the server-side synchronization feature. More information: Migrate settings from the Email Router to server-side synchronization
Cheers,
PMDY