让我们来看看官方文档是怎么讲的 https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg326836(v=crm.8)

Every time a running plug-in or Workflow issues a message request to the Web services that triggers another plug-in or Workflow to execute, the Depth property of the execution context is increased. If the depth property increments to its maximum value within the configured time limit, the platform considers this behavior an infinite loop and further plug-in or Workflow execution is aborted.

The maximum depth (8) and time limit (one hour) are configurable by the Microsoft Dynamics 365 administrator using the PowerShell command Set-CrmSetting. The setting is WorkflowSettings.MaxDepth. For more information, see, “Administer the deployment using Windows PowerShell” in the Deploying and administering Microsoft Dynamics CRM.

每当一个plugin或者workflow触发了一个请求到web service 并且触发了另一个plugin 和workflow去执行, Depth这个property会增长.如果在规定的时间内增长到最大值,CRM平台会认为这是一个infinit loop, 并且未来的plugin 和 worklow执行将会失败.

depth的最大值为8, 最大时间为1小时.

让我们创建一个ContextDepth.cs 的class

然后把以下的代码复制进去

// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity account = (Entity)context.InputParameters["Target"]; try
{
tracingService.Trace(context.Depth.ToString()); if (context.Depth > )
{
return;
} // In case the user removes the value
if (account.Attributes["revenue"] != null)
{
var revenue = ((Money)account.Attributes["revenue"]).Value;
revenue += ; account.Attributes["revenue"] = new Money(revenue);
}
} catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in MyPlug-in.", ex);
} catch (Exception ex)
{
tracingService.Trace("MyPlugin: {0}", ex.ToString());
throw;
}
}

让我们使用plugin registeration tool 把这个assembly register到crm中.

让我们改动 annual revenue的值

保存之后,我们发现annual revenue的值已经被更改

创建一个dynamics 365 CRM online plugin (九) - Context.Depth的更多相关文章

  1. 创建一个dynamics 365 CRM online plugin (七) - plugin当中的Impersonation角色

    我们之前创建的plugin都是使用default的 run in User's Context. 理解就是使用正在登陆的security context用户信息 那有个问题,如果当前用户的securi ...

  2. 创建一个dynamics 365 CRM online plugin (四) - PreValidation

    开始之前,我们要确认一下 Plugin 的 pipeline. PreValidation -> PreOperation -> Server Side System Main Event ...

  3. 创建一个dynamics 365 CRM online plugin (三) - PostOperation

    上两节我们创建了一个 PreOperation的plugin 今天我们创建一个PostOpeartion的plugin和之前的plugin连接起来 当创建contact之后,我们要添加一个task给新 ...

  4. 创建一个dynamics 365 CRM online plugin (一) - Hello World Plugin

    源代码连接:https://github.com/TheMiao/Dynamics365CRM/blob/master/MyCRM/MyCRM/HelloWorld.cs 首先,我们需要创建一个.NE ...

  5. 创建一个dynamics 365 CRM online plugin (十) - Isolation mode or trust mode

    Isolation Mode 也被称作为Plugin Trust CRM里面有两种plugin trust / isolation mode 1. Full Trust 只在OP系统中可使用,没有限制 ...

  6. 创建一个dynamics 365 CRM online plugin (五) - Images in Plugin

    Snapshots of the primary entity's attributes from database before(pre) and after (post) the core pla ...

  7. 创建一个dynamics 365 CRM online plugin (八) - 使用Shared Variables 在plugins 之前传递data

    CRM 可以实现plugin之前的值传递. 我们可以使用SharedVariables 把值在plugin之间传递 实现plugins之间的传递非常简单,我们只需要用key value pair来配对 ...

  8. 创建一个dynamics 365 CRM online plugin (六) - Delete plugin from CRM

    我们之前都学习到怎么添加,debug还有update plugin. 今天带大家过一下怎么从CRM instance当中删除plugin. 首先让我们打开Settings -> Customiz ...

  9. 创建一个dynamics 365 CRM online plugin (二) - fields检查

    Golden Rules 1. Platform only passes Entity attributes to Plugin that has change of data. 2. If the ...

随机推荐

  1. 初读"Thinking in Java"读书笔记之第七章 --- 复用类

    组合语法 将对象引用置于新类中,即形成类的组合. 引用初始化方法 在定义处初始化. 在类的构造器中初始化. 在使用这些对象之前,进行"惰性初始化". 使用实例初始化. 继承语法 J ...

  2. webpack-dev-server报错

    运行npm run dev报错,---- webpack-dev-server --inline --progress --config build/webpack.dev.conf.js npm E ...

  3. 体验ToLua框架下热更新(Phpstudy)

    一.关于热更新的详细流程 首先我们需要需要将本机电脑作为服务器打开,这是第一步 1.1.1如何确定我们的电脑是作为服务器打开的. 我们打开一个浏览器在地址栏中输入127.0.0.1.或者是localh ...

  4. Beta冲刺 3

    前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/10116813.html 作业博客:https://edu.cnblogs.com/campus ...

  5. oracle 语句导出 导入一张表语句

    导出: exp system/midsoft@bafy0929 file=d:\dzbl_models_temp.dmp tables=(emr.dzbl_models_temp) ; 导入:imp ...

  6. ivew Tooltip

    在使用ivew的Tooltip时发生错位,添加属性transfer,避免受父样式影响 发生如上错误时,只需添加属性transfer无需赋值

  7. 关于cordova+vue打包apk文件无法访问数据接口

    作为一个cordova小白,我按照官方文档和网上资料完成了讲vue文件打包到cordova中并打包成apk文件,完成了一个简单app的制作,当我正陶醉于可以自己完成一个app的时候突然发现,我的app ...

  8. 巧用string中的contains巧解一道题目

    题目:求0—7所能组成的奇数个数.假设最高八位数字. package edu.yuliang.lianxiti50; /* 题目:求0—7所能组成的奇数个数. *程序分析:最少也是1位数,最多能组成8 ...

  9. 跟技术胖学vue+koa

    首页热卖商品组件 技术点:1热卖商品封装成单独的组件  2路由和参数的传递  3详情页面路由参数的接收 //首页 <template> <div> <div class= ...

  10. 大数据 - hadoop三台linux虚拟服务器 - 初始化部署

    搭建hadoop环境 1.解压Hadoop的安装包,解压到modules文件夹中.(安装包下载地址:http://archive.apache.org/dist/hadoop/core/hadoop- ...