Microsoft CRM Plugin Infinite Loop

后端 未结 4 1399
孤城傲影
孤城傲影 2020-12-22 00:59

Another MS CRM question from me, I\'m afraid. I\'ve got the following code being executed on the update of a contact record but it gives me an error saying the job was cance

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 01:41

    At first if IExecutionContext.Depth <= 1 seems like a great idea, but it can bite you if you have a different plugin that updates the contact. You should be using the SharedVariables of the plugin context.

    Something like this should work:

    Add this declaration to the plugin class as a class level field:

    public static readonly Guid HasRunKey = new Guid("{6339dc20-01ce-4f2f-b4a1-0a1285b65bff}");
    

    And add this as the first step of your plugin:

    if(context.SharedVariables.ContainsKey[HasRunKey]){
        return;
    }else{
        context.SharedVariables.Add(HasRunKey);
        // Proceed with plugin execution
    }
    

提交回复
热议问题