博客原文:https://demystifyingcrm.wordpress.com/2014/12/17/trigger-plugin-for-nn-relationships-in-dynamics-crm/

wordpress在国内访问有点困难,怎么访问作为技术的你应该懂的

下面分享个我的示例,有助于你的理解,parameters总共有3个,Relationship(用来表示当前n:n关系的关系名称,见下面截图),Target和RelatedEntities分别对应的是两个实体,具体的还是看下面的代码就好

 public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
if (context.MessageName == "Associate")
{
if (context.Depth > 1)
{
return;
}
Relationship entityRelationShip = (Relationship)context.InputParameters["Relationship"];
if (entityRelationShip.SchemaName == "ubg_branch_product")//产品与分公司N:N的关联
{
EntityReferenceCollection RelatedEntity = (EntityReferenceCollection)context.InputParameters["RelatedEntities"];
Entity product = service.Retrieve(RelatedEntity[0].LogicalName, RelatedEntity[0].Id, new ColumnSet("ubg_approvestate"));
if (product.Attributes.Contains("ubg_approvestate") && ((OptionSetValue)product["ubg_approvestate"]).Value != 1)
{
throw new InvalidPluginExecutionException("非草稿状态的产品不允许关联分公司!");
}
}
if (entityRelationShip.SchemaName == "ubg_product_ubg_datalist")//产品与资料列表N:N的关联
{
EntityReference TargetEntity = (EntityReference)context.InputParameters["Target"];
Entity product = service.Retrieve(TargetEntity.LogicalName, TargetEntity.Id, new ColumnSet("ubg_approvestate"));
if (product.Attributes.Contains("ubg_approvestate") && ((OptionSetValue)product["ubg_approvestate"]).Value != 1)
{
throw new InvalidPluginExecutionException("非草稿状态的产品不允许资料!");
}
}
}
}

为了方便那些确实没办法访问wordpress的,我这里把注册的图也给贴出来

Dynamics CRM Trigger plugin for N:N relationships的更多相关文章

  1. Microsoft Dynamics CRM 2011 Plugin中PluginExecutionContext.InputParameters["Target"]中的Target是从哪来的?

    图 1 如图1,CRM编程是一个请求响应模型,任何操作都是通过一个Request发起,一个Response返回结果,这个模型简单实用.所有请求类都是继承OrganizationRequest,所有响应 ...

  2. Dynamics CRM 插件Plugin中获取和更新时间字段值的准确转换

    前面两篇介绍了后台代码通过组织服务获取更新时间字段.窗体javascript通过Odata获取更新时间字段,最后篇来实验下在插件中的获取和更新时间字段是否需要时制的转化,为何说是最后篇呢,因为在CRM ...

  3. Dynamics CRM - 使用 C# Plugin 调用 SQL 存储过程

    有时候,在 Dynamics CRM Plugin 中通过 linq 查询数据会比较慢,可以通过采用在 C# plugin 中直接调用数据库存储过程的方式来提高效率,具体过程如下: 1.新建一个存储过 ...

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

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

  5. 创建一个dynamics 365 CRM online plugin (九) - Context.Depth

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

  6. Dynamics 365 Customer Engagement导入解决方案时出错:Microsoft.Crm.CrmException: Plug-in assembly does not contain the required types or assembly content cannot be updated.

    我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...

  7. Dynamics CRM - 不同类型字段在 Plugin 里的赋值方式

    在编写 Plugin 代码之前,我们可以需要用 SDK bin 目录下的 CrmSvcUtil.exe 来将 CRM Site 上所有的 Entity 转换成类,而 Entity 里的 Field 也 ...

  8. Dynamics CRM - Plug-in Class 和 Workflow Class 的用法与区别

    在 Dynamics CRM 开发中,我们可以使用 JavaScript 在前端对 Entity Form 进行数据操作,与此同时,我们也可以使用 C# 写后台插件,其中就包括了 Plug-in Cl ...

  9. 一、Microsoft Dynamics CRM 4.0 SDK概述

    Chapter 1. Microsoft Dynamics CRM 4.0 SDK Overview(SDK概述) You are probably reading this book because ...

随机推荐

  1. 使用Vertx构建微服务

    Vertx Vert.x is a tool-kit for building reactive applications on the JVM.(Vertx是运行在JVM上用来构建reactive ...

  2. 前端开发必备之Chrome开发者工具(下篇)

    本文介绍的 Chrome 开发者工具基于 Chrome 65版本,如果你的 Chrome 开发者工具没有下文提到的那些内容,请检查下 Chrome 的版本 本文是 前端开发必备之Chrome开发者工具 ...

  3. A Neural Algorithm of Artistic Style 图像风格转换 - keras简化版实现

    前言 深度学习是最近比较热的词语.说到深度学习的应用,第一个想到的就是Prisma App的图像风格转换.既然感兴趣就直接开始干,读了论文,一知半解:看了别人的源码,才算大概了解的具体的实现,也惊叹别 ...

  4. svg 五花 元辅音 助读器

    如图,使用svg 创建5个圆,中间 辅音字母,外圈 元音字母 以及 示例单词. 可以使用  提交 按钮 进行更新

  5. Python数据抓取_BeautifulSoup模块的使用

    在数据抓取的过程中,我们往往都需要对数据进行处理 本篇文章我们主要来介绍python的HTML和XML的分析库 BeautifulSoup 的官方文档网站如下 https://www.crummy.c ...

  6. bzoj 2435: [Noi2011]道路修建

    Description 在 W 星球上有 n 个国家.为了各自国家的经济发展,他们决定在各个国家 之间建设双向道路使得国家之间连通.但是每个国家的国王都很吝啬,他们只愿 意修建恰好 n – 1条双向道 ...

  7. bzoj3825 NOI2017 游戏

    题目背景 狂野飙车是小 L 最喜欢的游戏.与其他业余玩家不同的是,小 L 在玩游戏之余,还精于研究游戏的设计,因此他有着与众不同的游戏策略. 题目描述 小 L 计划进行nn 场游戏,每场游戏使用一张地 ...

  8. Spring学习笔记3——使用注解的方式完成注入对象中的效果

    第一步:修改applicationContext.xml 添加<context:annotation-config/>表示告诉Spring要用注解的方式进行配置 <?xml vers ...

  9. C++中compile与build的区别

    我在前面的博文就提到了GCC编译器工作的四个阶段:预处理.编译.汇编.链接. 感兴趣的同学可以参考:http://www.cnblogs.com/mlgjb/p/7708007.html compil ...

  10. Python中的变量类型

    原文传送门:点击