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));}}}
Category: Dataverse
Dataverse lets you securely store and manage data that’s used by business applications. Data within Dataverse is stored within a set of tables. A table is a set of rows (formerly referred to as records) and columns (formerly referred to as fields/attributes)
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
DEBUG A PLUGIN – PERSIST TO ENTITY
There may be instances where you are debugging a plugin in Dynamics 365 and when you run the profiler, it produces the error “An error has occurred. The selected action was not completed for one or more records.” You may be running the profiler under the setting Exception: In order to get around the error, … Continue reading DEBUG A PLUGIN – PERSIST TO ENTITY
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