As per the Event Execution Pipeline for plugins in Dynamics 365, here we will look at a post-operation plugin. These plugins execute after the main system operation and within the database transaction. They can be synchronous and asynchronous. We have seen how to use pre-validation and pre-operation to update attribute values. In post-operation, the record is committed to the database, and the … Continue reading DYNAMICS 365 – POST-OPERATION PLUGIN
Month: November 2018
DYNAMICS 365 – PRE-OPERATION PLUGIN
As per the Event Execution Pipeline for plugins in Dynamics 365, here we will look at a pre-operation plugin. These plugins execute before the main system operation and within the database transaction. They run after the pre-validation has occurred. This is used for modifying/updating any attributes (note you can also technically do this in pre-validation). If you are creating a … Continue reading DYNAMICS 365 – PRE-OPERATION PLUGIN
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
DYNAMICS 365 – UNDERSTANDING PLUGIN DEPTH
In Dynamics 365, plugins have the concept of “depth”. This is how many times the plugin is firing based on certain events. The depth is part of the plugin context. Let’s go through an example of how plugin depth works. Create a new class library in Visual Studio: Add some code to check the depth: using … Continue reading DYNAMICS 365 – UNDERSTANDING PLUGIN DEPTH
DYNAMICS 365 – IMPERSONATE A USER IN PLUGIN
In Dynamics 365, when testing plugins, you can change which user the plugin runs under. Due to this, open the step in the Plugin Registration Tool. We have a plugin that runs on the creation of an account, that creates a new Task. We will select this to run under the context of a user, … Continue reading DYNAMICS 365 – IMPERSONATE A USER IN PLUGIN
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
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