Hi,
I am trying to create my first C# plugin for D365 online. I want to capture tracked emails before they are created in D365 and edit the body of the email (strip out some HTML out of the body to reduce the size of the storage required).
I can modify the "subject" of the email successfully but no matter what I do I cannot change the "description" (body) of the email entity. I don't get an error just nothing is changed.
I have registered the plugin step against Message=Create, Entity=email and as a Synchronous Pre-Operation.
My plugin is firing when I expect it to as I have confirmed this by throwing an error.
My code is as follows:
public void Execute(IServiceProvider serviceProvider)
{
// Plugin Step:
// Message: Create
// Primary Entity: email
// Run in Context: Calling User
// Pipeline Stage: PreOperation
// Execution Mode: Synchronous
// Deployment: Server
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.Contains("subject"))
{
entity["subject"] = "Plugin: Test Subject";
}
//Clean the description (body of the email)
if (entity.Contains("description"))
{
entity["description"] = "Plugin: Test Description";
}
}
Thanks,
Mark