博客原文: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. Convert.ToInt32、(int)和int.Parse三者的区别

    前者适合将object类类型转换成int类型 (int)适合简单数据类型之间的转换: int.Parse适合将string类类型转换成int类型.

  2. C#之FTP上传下载(二)

    这个类几乎包含了对FTP常用的方法,有不对的地方,欢迎批评指正 public class FtpClient { #region 构造函数 /// <summary> /// 创建FTP工 ...

  3. springcloud分布式事务终极探讨

    2018阿里云全部产品优惠券(好东东,强烈推荐)领取地址:https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userC ...

  4. hosts管理工具1.0发布了。。。。

    hosts管理工具1.0发布了.... 可以快速管理hosts文件了,再也不用打开系统盘,一个目录一个目录的查找了. 快速方便的修改host文件,一键保存. 可快速注释当前行,或者取消注释当前行,只需 ...

  5. 初学servlet之form表单

    使用doget向页面写表单,使用dopost读取表单内容,包括了单选按钮,复选框,下拉列表等等的读取方法,form的action属性不写,默认表单会被提交给请求他时用的相同的URL package a ...

  6. [WC2013]糖果公园

    Description 题库链接 给你一棵 $n$ 个节点,有 $m$种颜色的树.每个节点上有一个颜色.定义一条树上路径的价值为 $sum_c V_c(\sum_{i=1}^{tim_c}W_i)$ ...

  7. 线性规划与网络流24题●09方格取数问题&13星际转移问题

    ●(做codevs1908时,发现测试数据也涵盖了1907,想要一并做了,但因为“技术”不佳,搞了一上午) ●09方格取数问题(codevs1907  方格取数3) 想了半天,也没成功建好图: 无奈下 ...

  8. 【bzoj4568 scoi2016】幸运数字

    题目描述 A 国共有 n 座城市,这些城市由 n-1 条道路相连,使得任意两座城市可以互达,且路径唯一.每座城市都有一个幸运数字,以纪念碑的形式矗立在这座城市的正中心,作为城市的象征. 一些旅行者希望 ...

  9. ●BZOJ 2839 集合计数

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2839 题解: 容斥原理 真的是神题!!! 定义 f[k] 表示交集大小至少为 k时的方案数怎 ...

  10. bzoj3295[Cqoi2011]动态逆序对 树套树

    3295: [Cqoi2011]动态逆序对 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 5987  Solved: 2080[Submit][Sta ...