开发者

How to cancel create an cativity action on ms crm 4.0?

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)
                    {
          开发者_如何学C              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)
        {
        }
    }


Sounds like you are doing something wrong. You should probably post some of your code realting to the pre-checking and saving of the activity

You should have some logic like the following...

if(ValidateActivity()){
    CreateAndSaveActivity();
}
else
    throw execption;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜