Share annotation templates that are commonly used for writing plugins in normal times.
Plugin comment templates
/// <summary>
/// <list type="bullet">
/// <item>System Module: Pre-Sales (example)</item>
/// <item>Functionality</item>
/// <list type="number">
/// <item>Function description xxxx xxxx xxxx</item>
/// <item>Function description xxxx xxxx xxxx</item>
/// </list>
/// <item>Primary Entity: Account</item>
/// <item>Message: Update</item>
/// <item>Update Attributes: attributes 1, attributes 2</item>
/// <item>State: PostOperation</item>
/// <item>Mode: Synchronous</item>
/// </list>
/// </summary>
Message/State/Mode select
Tip
Convenient for direct copying and use.
- Message select
- Create
- Update
- Delete
- Associate
- Disassociate
- SetStateDynamicEntity
- RetrieveMultiple
- Retrieve
- QualifyLead
- Assign
- State select
- Pre-validation
- Pre-operation
- Post-operation
- Mode select
- Synchronous
- Asynchronous
Code Sample
using Microsoft.Xrm.Sdk;
using System;
namespace Blog.D365.Plugins.Account
{
/// <summary>
/// <list type="bullet">
/// <item>System Module: Pre-Sales (example)</item>
/// <item>Functionality</item>
/// <list type="number">
/// <item>Function description xxxx xxxx xxxx</item>
/// <item>Function description xxxx xxxx xxxx</item>
/// </list>
/// <item>Primary Entity: Account</item>
/// <item>Message: Update</item>
/// <item>Update Attributes: attributes 1, attributes 2</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"];
}
}
catch (Exception ex)
{
tracer.Trace($"AccountPostUpdate unexpected exception:\n{ex.Message}");
throw;
}
}
}
}
Thank you for your patience in reading! Come pick an emoji or leave a comment!