This is an accompanying blog post to my YouTube video Dynamics 365 Customer Engagement Deep Dive: Creating a Basic Plug-in, the second in a series aiming to provide tutorials on how to accomplish developer focused tasks within Dynamics 365 Customer Engagement. You can watch the video in full below:
Below you will find links to access some of the resources discussed as part of the video and to further reading topics:
PowerPoint Presentation (click here to download)
Full Code Sample
using System;
using System.Globalization;
using Microsoft.Xrm.Sdk;
namespace D365.SamplePlugin
{
public class PreContactCreate_FormatNameValues : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
//Extract the tracing service for use in debugging sandboxed plug-ins
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracingService.Trace("Tracing implemented successfully!");
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity contact = (Entity)context.InputParameters["Target"];
string firstName = contact.GetAttributeValue<string>("firstname");
string lastName = contact.GetAttributeValue<string>("lastname");
TextInfo culture = new CultureInfo("en-GB", false).TextInfo;
if (firstName != null)
{
tracingService.Trace("First Name Before Value = " + firstName);
contact["firstname"] = culture.ToTitleCase(firstName.ToLower());
tracingService.Trace("First Name After Value = " + contact.GetAttributeValue<string>("firstname"));
}
else
{
tracingService.Trace("No value was provided for First Name field, skipping...");
}
if (lastName != null)
{
tracingService.Trace("Last Name Before Value = " + lastName);
contact["lastname"] = culture.ToTitleCase(lastName.ToLower());
tracingService.Trace("Last Name After Value = " + contact.GetAttributeValue<string>("lastname"));
}
else
{
tracingService.Trace("No value was provided for Last Name field, skipping...");
}
tracingService.Trace("PreContactCreate_FormatNameValues plugin execution complete.");
}
}
}
}
Download/Resource Links
Visual Studio 2017 Community Edition
Setup a free 30 day trial of Dynamics 365 Customer Engagement
Source Code Management Solutions
- Visual Studio Team Services – Free for up to 5 users and my recommended choice when working with Dynamics 365 Customer Engagement
- BitBucket
- GitHub
Further Reading
MSDN – Supported messages and entities for plug-ins
MSDN – Sample: Create a basic plug-in
I’ve written a number of blog posts around plug-ins previously, so here’s the obligatory plug section
:
- Why CRM Developers Should Use Business Rules More – The post talks more about Business Rules in the context of JScript, but echoes some of the points made in the video in respect to considering plug-ins as a “last resort” solution.
- What is Unsecure/Secure Configuration on a Dynamics CRM/365 for Enterprise Plugin? – Unsecure/Secure Configurations are, arguably, one of those features that people tend to forget about with plug-ins; this post walks through how to implement them within your code.
- Utilising Pre/Post Entity Images in a Dynamics CRM Plugin – One of the best features at your disposal with plug-ins, Entity Images allow you to take snapshots of record data before and after your plug-in executes, and then access this data during runtime.
- What’s the best way of learning CRM Development? – In this post, I talk about some of the things that you can do to help speed your journey towards Dynamics 365 Customer Engagement developer extraordinaire


Like
Report
*This post is locked for comments