开始之前,我们要确认一下 Plugin 的 pipeline. PreValidation -> PreOperation -> Server Side System Main Event-> PostOperation

PreValidation 是在security check 之前, 通常会用来加载外部数据和用户不相关的内容.
PreOperation 是在security check 之后 服务器处理之前, 通常会用来做一系列的功能.
PostOperation 是在System Main Event 在服务器处理发生之后, 通常是用来对Event做一些额外添加.

Database Transaction Support

DTS 值在PreOperation 和PostOperation中有效.

DTS是 当你有exception的时候, 你的所有的data 都会roll back 不会记录到数据库中. 只有完全execute的Plugin的数据才会储存

我们开始做我们第三个plugin.  PreValidation

这个Plugin的功能是查重. 是的,虽然系统内置有查重功能,但是为了做PreValidation的plugin,我们实现一下.

这里我们用QueryExpression用来查询email address

// Plug-in business logic goes here.
string email = string.Empty; if (contact.Attributes.Contains("emailaddress1"))
{
email = contact.Attributes["emailaddress1"].ToString(); // Now we need use query to retrieve email
// select * from contact where emailaddress1 == 'email' var query = new QueryExpression("contact");
query.ColumnSet = new ColumnSet(new string[] { "emailaddress1" });
query.Criteria.AddCondition("emailaddress1", ConditionOperator.Equal, email); var collection = service.RetrieveMultiple(query); if (collection.Entities.Count > )
{
throw new InvalidPluginExecutionException("Contact with email already exists!!!");
}
}

我们把代码复制到try里面之后rebuild. 用PluginRegistration tool把代码重新部署到instance当中.

之后我们创建一个contact填写好邮箱,用contact2来填写相同邮箱.

这时候就会出现我们的bug

让我们打开Error Log 发现我们的message是之前代码中编译好的.

创建一个dynamics 365 CRM online plugin (四) - PreValidation的更多相关文章

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

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

  2. 创建一个dynamics 365 CRM online plugin (七) - plugin当中的Impersonation角色

    我们之前创建的plugin都是使用default的 run in User's Context. 理解就是使用正在登陆的security context用户信息 那有个问题,如果当前用户的securi ...

  3. 创建一个dynamics 365 CRM online plugin (三) - PostOperation

    上两节我们创建了一个 PreOperation的plugin 今天我们创建一个PostOpeartion的plugin和之前的plugin连接起来 当创建contact之后,我们要添加一个task给新 ...

  4. 创建一个dynamics 365 CRM online plugin (一) - Hello World Plugin

    源代码连接:https://github.com/TheMiao/Dynamics365CRM/blob/master/MyCRM/MyCRM/HelloWorld.cs 首先,我们需要创建一个.NE ...

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

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

  6. 创建一个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 ...

  7. 创建一个dynamics 365 CRM online plugin (八) - 使用Shared Variables 在plugins 之前传递data

    CRM 可以实现plugin之前的值传递. 我们可以使用SharedVariables 把值在plugin之间传递 实现plugins之间的传递非常简单,我们只需要用key value pair来配对 ...

  8. 创建一个dynamics 365 CRM online plugin (六) - Delete plugin from CRM

    我们之前都学习到怎么添加,debug还有update plugin. 今天带大家过一下怎么从CRM instance当中删除plugin. 首先让我们打开Settings -> Customiz ...

  9. 创建一个dynamics 365 CRM online plugin (二) - fields检查

    Golden Rules 1. Platform only passes Entity attributes to Plugin that has change of data. 2. If the ...

随机推荐

  1. 编译libcurl支持https协议

    编译与安装参考:http://www.cnblogs.com/openiris/p/3812443.html 注意事项:先下载安装完nasm和perl再打开控制台(需要将nasm安装路径添加到Path ...

  2. ajax 提交form格式 和 json格式

    json 格式 内容在body中 ajax设置   Content-Type: application/json 浏览器查看为 Request Payload The Request Payload ...

  3. 共有和私有、name mangling

    1.在python中可以在变量和函数名前加上双下划线—‘’__‘’来实现其伪私有(实际上python中没有Private属性的),加上双下划线后,外部对象不能通过调用其名称直接获得对象的属性或操作. ...

  4. RabbitMQ中的RPC实现

    1.RPC简述 RPC,Remote Procedure Call 远程过程调用.通俗讲,两段程序不在同一个内存空间,无法直接通过方法名调用,就需要通过网络通信方式调用.对于RabbitMQ,本身就是 ...

  5. python笔记——随手记

    1.max与min函数的使用min(0)返回该矩阵中每一列的最小值 min(1)返回该矩阵中每一行的最小值 max(0)返回该矩阵中每一列的最大值 max(1)返回该矩阵中每一行的最大值2.argso ...

  6. 利用toggle实现背包

    1.先创建入如图所示界面 2.在图片下面创建一个选中状态图片 3.在normal图片添加toggle组件,将子物体拖动到graphic里

  7. python学习第三次记录

    python学习第三次记录 python中常用的数据类型: 整数(int) ,字符串(str),布尔值(bool),列表(list),元组(tuple),字典(dict),集合(set). int.数 ...

  8. Windows10 VS2017 C++多线程传参和等待线程结束

    #include "pch.h" #include <iostream> #include <windows.h> using namespace std; ...

  9. Windows10 VS2017 C++模拟点击按键

    #include "pch.h" #include <Windows.h> #include <stdio.h> #include <iostream ...

  10. spring cloud_1_mm_eureka2 eureka集群

    一个eureka会出现单点故障 这里整两个 eureka--1 application.yml: #注册中心端口 server: port: 8888 #唯一标示eureka注册中心 方便互相识别 e ...