在标准实体特殊消息上注册插件及Dynamics CRM 2015中计算字段的使用
| 状态 | Status | 状态值 | 状态描述 | Status Reason | 状态描述值 |
| 可用 | Active | 0 | 正在进行 | In Progress | 1 |
| 暂侯 | On Hold | 2 | |||
| 等待详情 | Waiting for Details | 3 | |||
| 正在研究 | Researching | 4 | |||
| 已解析 | Resolved | 1 | 问题已解决 | Problem Solved | 5 |
| 提供的信息 | Information Provided | 1000 | |||
| 已取消 | Canceled | 2 | 已取消 | Canceled | 6 |
| 合并 | Merged | 2000 |




为了方便查看结果,我还在公共视图 可用案例 、 所有案例 、 已解决案例 、快速查找案例 四个视图中添加显示列 解决者 和 解决时间 两个列。





protected void ExecutePreCaseClose(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
} // TODO: Implement your custom Plug-in business logic.
IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
Entity incidentResolutionEntity = context.InputParameters.Contains("IncidentResolution") ? (Entity)context.InputParameters["IncidentResolution"] : null;
if (incidentResolutionEntity != null)
{
Entity incidentEntity = service.Retrieve("incident", incidentResolutionEntity.GetAttributeValue<EntityReference>("incidentid").Id, new ColumnSet("new_resolvedby"));
incidentEntity["new_resolvedby"] = new EntityReference("systemuser", context.InitiatingUserId);
service.Update(incidentEntity);
}
}


我们知道案例是可以重新激活的,也可以取消的,从前面的博文知道,我们需要在 SetStateDanamicEntity消息上注册插件,我这里注册的插件如下,注意要使用Post-Operation 阶段,这也是考虑到案例在某些状态下只读。

protected void ExecutePostCaseSetStateDynamicEntity(LocalPluginContext localContext)
{
try
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
} IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null; // TODO: Implement your custom Plug-in business logic.
OptionSetValue preStateCode = preImageEntity.Contains("statecode") ? preImageEntity.GetAttributeValue<OptionSetValue>("statecode") : null;
OptionSetValue preStatusCode = preImageEntity.Contains("statuscode") ? preImageEntity.GetAttributeValue<OptionSetValue>("statuscode") : null;
if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference)
{
EntityReference currentEntityRef = (EntityReference)context.InputParameters["EntityMoniker"];
OptionSetValue postStateCode = context.InputParameters.Contains("State") ? (OptionSetValue)context.InputParameters["State"] : null;
OptionSetValue postStatusCode = context.InputParameters.Contains("Status") ? (OptionSetValue)context.InputParameters["Status"] : null;
var noteText = new StringBuilder("SetStateDynamicEntity消息执行前的statecode字段值为:");
noteText.Append(preStateCode == null ? "null" : preStateCode.Value.ToString());
noteText.Append(";statuscode字段值为:");
noteText.Append(preStatusCode == null ? "null" : preStatusCode.Value.ToString());
noteText.Append(";SetStateDynamicEntity消息执行时要将的statecode字段值变更为:");
noteText.Append(postStateCode == null ? "null" : postStateCode.Value.ToString());
noteText.Append(";statuscode字段值变更为:");
noteText.Append(postStatusCode == null ? "null" : postStatusCode.Value.ToString());
Entity noteEntity = new Entity("annotation");
noteEntity["isdocument"] = false;
noteEntity["notetext"] = noteText.ToString();
noteEntity["objectid"] = currentEntityRef;
noteEntity["subject"] = "微软MVP罗勇测试SetStateDynamicEntity消息";
service.Create(noteEntity);
//下面才是本篇博文新增的代码,其余的代码和前面博文的代码十分类似
//如果变更状态前是已解析,变更状态后不是已解析,则需要设置解决者字段为空值Null
if (preStateCode != null && preStateCode.Value == && postStateCode != null && postStateCode.Value != )
{
Entity incidentEntity = service.Retrieve("incident", currentEntityRef.Id, new ColumnSet("new_resolvedby"));
incidentEntity["new_resolvedby"] = null;
service.Update(incidentEntity);
}
}
else
{
throw new Exception(@"输入参数中不包括EntityMoniker参数,或者包括了EntityMoniker参数但是其类型不是实体引用");
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(@"执行消息SetStateDynamicEntity的Post阶段插件出错:" + ex.Message + ex.StackTrace);
}
}


而且 解决者 和 解决时间字段的内容也是空值了,正确。


在标准实体特殊消息上注册插件及Dynamics CRM 2015中计算字段的使用的更多相关文章
- 在Dynamics CRM 2015中通过3CX插件(以及3CX windows phone)拨出电话
背景 在On-premises部署的Dynamics CRM中实现通过网页拨通客户电话的功能 要点 3CX 提供了开箱即用的Dynamics CRM Solution,只需要在Microsoft Dy ...
- Dynamics 365中计算字段与Now进行计算实体导入报错:You can't use Now(), which is of type DateTime, with the current function.
微软动态CRM专家罗勇 ,回复338或者20190521可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me. 计算字段是从Dynamics CRM 2015 SP1版本开始推 ...
- Dynamics CRM 2015/2016新特性之三十四:有了插件日志,调试插件so easy!
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复217或者20160330可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...
- 在VM虚拟机Windows Server r2上部署安装Microsoft Dynamics CRM 2016 步骤详解(一)
应公司需求,最近在学微软的Dynamics CRM.在搭建环境的过程中也遇到了一些雷坑,在这里分享一下安装部署过程当中所遇到的一些问题, 安装Microsoft Dynamics CRM 2016的几 ...
- Dynamics CRM 365中结合注释和WebApi实现图片上传
首先需要在实体上使用注释,然后在窗体上引用WebResource. WebResource的代码: <!DOCTYPE html> <html> <head> &l ...
- Dynamics CRM 2015 站点地图公告配置实体显示名称的变更
CRM更新2015后,在设置里找不到公告配置了 在原来的位置上你会东西一个叫活动源配置的东西,点开看后就是原来的公告配置.
- Dynamics 365中开发和注册插件介绍
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- Flutter Toast消息提示框插件
Flutter Toast消息提示框插件 在开发flutter项目中,想必大家肯定会用到toast消息提示,说到这里, 大家肯定会想到https://pub.dev/ 插件库, 但是插件市场上有太多类 ...
- Microsoft Dynamics CRM 2011 新建实体 需要注意的细节
新建一个实体,需要红色框内的是否勾选的意义,可以进一步加深对CRM的理解.如图: 下面对部分的进行了自我的理解,不对的地方,还请大家指出来.互相学习. 1.CRM2011中,在活动方面加强的新特性包括 ...
随机推荐
- Linux中环境变量相关文件的区别
Linux下各种不同环境变量相关文件的作用: 1. /etc/environment 设置整个系统的环境,系统启动时,该文件被执行. 2. /etc/profile 设置所有用户的环境,当用 ...
- 《Dotnet9》系列之建站-Dotnet9建站20天感悟
本人站点 https://dotnet9.com,建站20天了,在这给站长朋友讲述个人建站经历,希望对大家能有所帮助. https://dotnet9.com 网站采用 宝塔 + WordPress ...
- C#中的Skip()和Take()
Skip()和Take()方法都是IEnumerable<T> 接口的扩展方法,包括C#中的所有Collections类,如ArrayList,Queue,Stack等等,还有数组和字符串 ...
- 在IIS上部署 .Net Core 3.0 项目踩坑实录
在IIS上部署 .Net Core 3.0 项目的主要流程有: 安装并启用IIS 安装AspNetCoreModuleV2 添加.配置网站 设置应用程序池 通过VS发布 一.安装并启用IIS: 安装了 ...
- Angular(06)- 为什么数据变化,绑定的视图就会自动更新了?
这里提一点,前端三大框架(Angular,React,Vue)的数据驱动来更新视图的原理,即 MVVM 的实现. 为什么数据发生变化,绑定的视图就会刷新了呢? 以下是我的个人理解,仅供参考: 在还是 ...
- JS---DOM---tab切换案例实现---排他
tab切换案例实现 <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...
- Dynamics 365 Customer Engagement的标准导入不支持并行导入了吗?
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- [转]BEC Vantage
https://www.examenglish.com/BEC/BEC_Vantage.html https://www.cambridgeenglish.org/exams-and-tests/bu ...
- 服务守护DOS脚本
创建一个批处理文件,复制以下内容至文件中并保存,右键文件名,以管理员身份运行. @@@code @echo off @echo 请使用管理员身份运行此脚本 rem 运行前先打开文件修改下列变量: ...
- JavaScript banner轮播 左右切换 圆点点击切换
1.效果如下图: 2.源码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...