On creating opportunity record if plugin is registered for Update event then it will automatically trigger and the code written for the Update event will be executed, to prevent from this erroneously behavior you can add a condition to check if plugin parent Context execution message is null then execute the code.
[Plugin: C# Code]
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Text; |
using Microsoft.Xrm.Sdk; |
using Microsoft.Xrm.Sdk.Metadata; |
using Microsoft.Crm.Sdk; |
namespace wod.Crm.PluginDebugger |
{ |
public class wodPlugin : IPlugin |
{ |
public void Execute(IServiceProvider serviceProvider) |
{ |
// Obtain the execution context from the service provider. |
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); |
// check if parenet context message is Create and current contetx message is Update then return //and does not execute code. |
if (context.MessageName == "Update" && context.ParentContext != null && context.ParentContext.MessageName == "Create") |
{ |
return; |
} |
else |
{ |
// Write your update Opportunity record code here |
} |
} |
} |
} |