博客原文: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. [LeetCode] Find Mode in Binary Search Tree 找二分搜索数的众数

    Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred ...

  2. python系列之 - 并发编程(进程池,线程池,协程)

    需要注意一下不能无限的开进程,不能无限的开线程最常用的就是开进程池,开线程池.其中回调函数非常重要回调函数其实可以作为一种编程思想,谁好了谁就去掉 只要你用并发,就会有锁的问题,但是你不能一直去自己加 ...

  3. webpack构建react项目(一)

    前言 下面是我们使用到技术栈: webpack + react + redux + react-router + react-thunk + ES6 + .... 注意事项: 建议使用npm5.X 或 ...

  4. servlet之cookie实现

    三个servlet的实现: package app02c;import java.io.IOException;import java.io.PrintWriter;import javax.serv ...

  5. [APIO 2012]派遣

    Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿. 在这个帮派里,有一名忍者被称之为Master.除了Master以外,每名忍者都有且仅有一个上级.为 ...

  6. BZOJ 3243 Clever Y

    Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, ...

  7. [SDOI2009]学校食堂Dining

    题目描述 小F 的学校在城市的一个偏僻角落,所有学生都只好在学校吃饭.学校有一个食堂,虽然简陋,但食堂大厨总能做出让同学们满意的菜肴.当然,不同的人口味也不一定相同,但每个人的口味都可以用一个非负整数 ...

  8. 51 nod 1766 树上的最远点对(线段树+lca)

    1766 树上的最远点对 基准时间限制:3 秒 空间限制:524288 KB 分值: 80 难度:5级算法题   n个点被n-1条边连接成了一颗树,给出a~b和c~d两个区间,表示点的标号请你求出两个 ...

  9. 【BZOJ3631】【JLOI2014】松鼠的新家

    原题传送门 题意:给你一棵树,然后有一个遍历顺序,你需要补全这个遍历顺序,然后输出这个遍历顺序中每个点的出现次数. 解题思路:本来想找树剖的题,结果发现了一题可以直接写lca的.... 做法1:非常简 ...

  10. dp之背包总结篇

    //新手DP学习中 = =!! 前言:背包问题在dp中可以说是经典,作为一个acmer,到现在才正式学习dp,可以说是比较失败的.我个人比较认同一点,想要做一个比较成功的acmer,dp.搜索.数学必 ...