i have a plugin for an activity.
on pre create i check few conditions and if i get true so i throw OperationCanceledException for stop the create execution.
but the record was saved, why? how do i can to cancel the creation? also tried to throw InvalidPluginExecutionException, but it's stil executed..
the code:
public void Execute(IPluginExecutionContext context)
{
try
{
switch (context.MessageName)
{
case "Create":
if (context.Stage == MessageProcessingStage.BeforeMainOperationOutsideTransaction)
{
bool shouldnotcreateactivity = Create(context, service);
if (shouldnotcreateactivity)
throw new OperationCanceledException();
}
if (context.OutputParameters.Properties.Contains("id"))
{
//continue...
}
break;
}
}
catch (OperationCanceledException cancled)
{
}
catch (InvalidPluginExecutionException invalid)
{
}
catch (SoapException ex)
{
}
catch (Exception ex)
{
}
}