D365 – Plugin Comment Template

Introduction

When implementing Dynamics 365 projects, writing plugins is a common way to extend functionality and meet customized requirements. If there are multiple developers working on the same project, plugin comments are essential. Correctly commenting plugins can help others better understand the purpose and functionality of the code.

Below is a comment template for Dynamics 365 plugins, along with some sample code. This is the template I usually use. If there are any immature aspects in this template, feedback and corrections are welcome.

CSHARP
/// <summary>
/// <list type="bullet">
/// <item>Module: Pre-sales (example)</item>
/// <item>Function</item>
/// <list type="number">
/// <item>Function description xxxx xxxx xxxx</item>
/// <item>Function description xxxx xxxx xxxx</item>
/// </list>
/// <item>Primary Entity: Lead</item>
/// <item>Message: Update</item>
/// <item>Update Attributes: qualifyingopportunityid, statecode</item>
/// <item>State: PostOperation</item>
/// <item>Mode: Synchronous</item>
/// </list>
/// </summary>
Click to expand and view more

Message/State/Mode Options

Example

CSHARP
using Microsoft.Xrm.Sdk;
using System;

namespace Blog.D365.Plugins.Account
{
    /// <summary>
    /// <list type="bullet">
    /// <item>Module: Pre-sales (example)</item>
    /// <item>Function</item>
    /// <list type="number">
    /// <item>Function description xxxx xxxx xxxx</item>
    /// <item>Function description xxxx xxxx xxxx</item>
    /// </list>
    /// <item>Primary Entity: Lead</item>
    /// <item>Message: Update</item>
    /// <item>Update Attributes: qualifyingopportunityid, statecode</item>
    /// <item>State: PostOperation</item>
    /// <item>Mode: Synchronous</item>
    /// </list>
    /// </summary>
    public class AccountPostUpdate : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            try
            {
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = factory.CreateOrganizationService(context.UserId);
                    IOrganizationService serviceAdmin = factory.CreateOrganizationService(null);                    
                    Entity currentEntity = (Entity)context.InputParameters["Target"];
                    
                    // Add your plugin logic code here

                }
            }
            catch (Exception ex)
            {
                tracer.Trace($"AccountPostUpdate unexpected exception:\n{ex.Message}");
                throw;
            }
        }
    }
}
Click to expand and view more

Copyright Notice

Author: Donghai

Link: https://gdhblog.com/posts/d365/plugin-comment-template/

License: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

Comments

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut