DYNAMICS 365 – PRE-VALIDATION PLUGIN

As per the Event Execution Pipeline for plugins in Dynamics 365, here we will look at a pre-validation plugin. These plugins execute before the main system operation and outside the database transaction. Pre-validation runs before validation occurs. You can also modify values at this stage, though this may be generally done in pre-operation. If you are creating a record, … Continue reading DYNAMICS 365 – PRE-VALIDATION PLUGIN

DYNAMICS 365 PLUGIN EXECUTION PIPELINE

In Dynamics 365, when a plugin is run, it executes based on a pipeline execution model. Plugins can be triggered by: A user action in the Dynamics 365 user interface, such as retrieving a recordEvents triggered by the Organization Service or the WebAPI, such as retrieving a record Post-Operation events in the pipeline are processed … Continue reading DYNAMICS 365 PLUGIN EXECUTION PIPELINE

USING PLUGIN TRACE LOG TO TRACE PLUGIN EXCEPTIONS IN DYNAMICS 365

In Dynamics 365, you can add tracing to your code to assist with troubleshooting. To do this, in your plugin, add the code: ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); Then add a line to do the trace: tracingService.Trace("This is a trace."); Next, go to System Settings to actually turn tracing on in the system: Under Customization, you … Continue reading USING PLUGIN TRACE LOG TO TRACE PLUGIN EXCEPTIONS IN DYNAMICS 365

DYNAMICS 365 – PLUGIN QUICK CODE

The following is a code snippet to get a plugin up and running quickly. In NuGet, add Microsoft.CrmSdk.CoreAssemblies using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Query; namespace Carl.PluginName{public class PluginName : IPlugin{public void Execute(IServiceProvider serviceProvider){IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));}}}

DYNAMICS 365 – PLUGIN EXECUTION QUERY

In Dynamics 365, when a plugin is executed, we can determine the query type that caused the plugin to fire through the IPluginExecutionContext in Microsoft.Xrm.Sdk. In the example below, if we run to create a simple plugin that runs on RetrieveMultiple, and display Active Accounts in the Dynamics 365 user interface, our plugin execution context will contain in … Continue reading DYNAMICS 365 – PLUGIN EXECUTION QUERY

DYNAMICS 365 RAISE ERROR IN PLUGIN

To raise an error in the plugin code, we use InvalidPluginExecutionException. For example: throw new InvalidPluginExecutionException("Plugin has run. Code will stop executing."); The code runs in the Execute function of the plugin code. For example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; namespace Carl.AssociateDisassociate {      public class AssociateDisassociate : IPlugin { public void Execute(IServiceProvider serviceProvider)         {             throw new InvalidPluginExecutionException("Plugin has run. Code will stop executing.");          }     }} The code will display the error and stop executing: If you … Continue reading DYNAMICS 365 RAISE ERROR IN PLUGIN

CREATING AND DEBUGGING A PLUGIN IN DYNAMICS CRM

The Dynamics CRM 2016 SDK contains a plugin sample. The code is located here: SDK\SampleCode\CS\Plug-ins\AccountNumberPlugin.cs I’m going to go through step by step how to create this plugin and upload it to Dynamics CRM, then how to debug the plugin. In the example I will connect to a Dynamics CRM 2016 Online instance. Firstly, open and build the … Continue reading CREATING AND DEBUGGING A PLUGIN IN DYNAMICS CRM

CREATING A DYNAMICS CRM PLUGIN FROM SCRATCH

Here I will go through an example of creating a Dynamics CRM plugin. In this example, I will create a plugin to set the opportunity description after the opportunity has been created. First create a new project in Visual Studio. Next, add references. Add the Microsoft.Xrm.Sdk.dll which is found in the CRM SDK at CRM SDK 2016\SDK\Bin … Continue reading CREATING A DYNAMICS CRM PLUGIN FROM SCRATCH