创建一个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 反射与其应用
前言: 目标:对于我个人而言 我希望能由以下途径达到最终目标 清楚反射的概念以及为什么要用反射技术 -> java的反射技术 -> java反射技术涉及到的类 -> java反射技 ...
- 用java代码作日历
import java.util.Calendar; public class CalendarBean { String day[]; int year=2005,month=0; public v ...
- jQuery对象和普通DOM对象的区别
1.DOM对象DOM实际上是以面向对象方式描述的文档模型.DOM定义了表示和修改文档所需的对象.这些对象的行为和属性以及这些对象之间的关系.根据W3C DOM规范,DOM是HTML与XML的应用编程接 ...
- 使用IdentityServer4,在一个ASPNetCore项目中,配置oidc和api的AccessToken两种认证授权
1.配置两种认证方式 JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); services.AddAuthentication(op ...
- 用indexof来统计字符出现的次数
代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- IIC_slaver 仿真错误
integer 类型不能直接赋值. 改正之后的代码
- 字符串排序简单的工具类,数组转list,list转数组
public static void main(String[] args) { /* String[] str = {"a", "c", "b&qu ...
- Filter 中空指针错误
Filter 是过滤器,凡是通过servlet JSP 的请求需要filter 进行过滤或者拦截操作,保证数据的合法或者逻辑正确性 但是写第一个filter 配置完成后,发现jsp 文件进不去了,直 ...
- Python 常见字符串常量和表达式
常见字符串常量和表达式 操作 解释 s = '' 空字符串 s = "spam's" 双引号和单引号相同 S = 's\np\ta\x00m' 转义序列 s = "&qu ...
- oracle针对某列让特定信息排序[decode]
在ORACLE查询中,如果在没有排序,但又想让某列中特定值的信息排到前面的时候,使用oracle的decode(字段,'字段值',数字) 如 select name from user 查询出来的所有 ...