创建一个dynamics 365 CRM online plugin (九) - Context.Depth
让我们来看看官方文档是怎么讲的 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的更多相关文章
- 创建一个dynamics 365 CRM online plugin (七) - plugin当中的Impersonation角色
我们之前创建的plugin都是使用default的 run in User's Context. 理解就是使用正在登陆的security context用户信息 那有个问题,如果当前用户的securi ...
- 创建一个dynamics 365 CRM online plugin (四) - PreValidation
开始之前,我们要确认一下 Plugin 的 pipeline. PreValidation -> PreOperation -> Server Side System Main Event ...
- 创建一个dynamics 365 CRM online plugin (三) - PostOperation
上两节我们创建了一个 PreOperation的plugin 今天我们创建一个PostOpeartion的plugin和之前的plugin连接起来 当创建contact之后,我们要添加一个task给新 ...
- 创建一个dynamics 365 CRM online plugin (一) - Hello World Plugin
源代码连接:https://github.com/TheMiao/Dynamics365CRM/blob/master/MyCRM/MyCRM/HelloWorld.cs 首先,我们需要创建一个.NE ...
- 创建一个dynamics 365 CRM online plugin (十) - Isolation mode or trust mode
Isolation Mode 也被称作为Plugin Trust CRM里面有两种plugin trust / isolation mode 1. Full Trust 只在OP系统中可使用,没有限制 ...
- 创建一个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 ...
- 创建一个dynamics 365 CRM online plugin (八) - 使用Shared Variables 在plugins 之前传递data
CRM 可以实现plugin之前的值传递. 我们可以使用SharedVariables 把值在plugin之间传递 实现plugins之间的传递非常简单,我们只需要用key value pair来配对 ...
- 创建一个dynamics 365 CRM online plugin (六) - Delete plugin from CRM
我们之前都学习到怎么添加,debug还有update plugin. 今天带大家过一下怎么从CRM instance当中删除plugin. 首先让我们打开Settings -> Customiz ...
- 创建一个dynamics 365 CRM online plugin (二) - fields检查
Golden Rules 1. Platform only passes Entity attributes to Plugin that has change of data. 2. If the ...
随机推荐
- 用java代码作日历
import java.util.Calendar; public class CalendarBean { String day[]; int year=2005,month=0; public v ...
- 利用Django实现webUI展示
1.说明 最近老大想要做一个webUI界面,为了展示我们数据中心工作内容,需要把各自的工作内容用webUI展示出来.目前我负责的做公司名称归一化的问题. 2.Django实现web 具体实现是完全按照 ...
- Spring源码学习(5)—— bean的加载 part 2
之前归纳了从spring容器的缓存中直接获取bean的情况,接下来就需要从头开始bean的加载过程了.这里着重看单例的bean的加载 if(ex1.isSingleton()) { sharedIns ...
- L360 Most People Spend Their Time in Just 25 Places
Some people are always out on the town, going to concerts, restaurant openings, you name it. They're ...
- HTML表格布局
1 浏览器:接受浏览者的操作,然后帮浏览者去web服务器请求网页内容,然后展现成人人眼能够看得懂的可视化页面的软件. 2 IE是浏览器的一种.<ietest工具& ...
- Scrapy创建项目问题
创建项目时报错 ModuleNotFoundError: No module named 'cryptography.hazmat.bindings._constant_time' pip insta ...
- Java的类型强制转换
不说基本类型,没什么意思. 小括号的类型转换,在引用上,表示我坚定的确信,该未知类型一定是我转的类型,或者是我转的类型的子类. 这个转换逻辑和基本类型是不一致的.它不会进行任何具体的操作,只是一种标识 ...
- java 二分法学习
假设有一个数组 { 12, 23, 34, 45, 56, 67, 77, 89, 90 },现要求采用二分法找出指定的数值并将其在数组的索引返回,如果没有找到则返回 -1.代码如下: package ...
- windows.h详解
参考 http://blog.csdn.net/fengningning/article/details/2306650?locationNum=1&fps=1 windows.h解构 刚开头 ...
- 最新版本汉化-PowerDesigner 16.6 汉化并河蟹
更新日志: 2019-03-14 V1.1 1.支持反复多次汉化: 2.修复少许bug. 最新的16.6版本已经在汉化中了,基本上所有的菜单均已汉化完成,部分窗体还没有编译通过. 不过,不影响尝鲜使用 ...