Skip to content

Instantly share code, notes, and snippets.

@dtaivpp
Last active August 2, 2019 16:52
Show Gist options
  • Save dtaivpp/8f187e16b6d40e1bc3557d466f8d4885 to your computer and use it in GitHub Desktop.
Save dtaivpp/8f187e16b6d40e1bc3557d466f8d4885 to your computer and use it in GitHub Desktop.
Dynamics CRM Basic Plugin
using System;
using Microsoft.Xrm.Sdk;
namespace CRM.BusinessUnit.Plugins
{
// Attributes used to simplify creating plugins
[StepMessage, StepEntity, SetpStage, StepMode, StepId]
[StepPreImage, PreImageId]
[StepPostImage, StepPostImageId]
public class org_ContactPreCreatePlugin : Pluginbase IPlugin
{
public org_ContactPreCreatePlugin(): base() {}
public override void Execute (ExecutionContext, OrgService, DataContext)
{
// Grab data needed from crm here (pre / post image data and other associated entities)
var entity = (Entity).InputParameters[Microsoft.Crm.Sdk.ParameterName.Target];
var contact = entity.ToEntity<org_ContactEntity>;
// Here call the business logic that needs to be executed to modify the contact
contact = BusinessLogic.org_ContactPreCreateBusinessLogic.Run(contact);
// Finally return the modified entity to the CRM
context.InputParameters[Microsoft.Crm.Sdk.ParameterName.Target] = continuity.ToEntity<Entity>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment