在Dynamis CRM中打造一键保存关闭刷新案例的功能
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复172或者20151114可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me!


function CloseCaseAsResolved(CaseId, FormOrList) {
if (FormOrList == "Form" && Xrm.Page.data.entity.getIsDirty()) {
Xrm.Page.data.save(true).then(function () {
ExecuteCloseIncidentRequestRequest(CaseId, FormOrList, true);
}, function (errorCode, message) {
Xrm.Utility.alertDialog("Save record error." + message);
});
}
else {
ExecuteCloseIncidentRequestRequest(CaseId, FormOrList, false);
}
}
function ExecuteCloseIncidentRequestRequest(CaseId, FormOrList, IsDirty) {
var requestMain = ""
requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestMain += " <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:CloseIncidentRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>IncidentResolution</c:key>";
requestMain += " <c:value i:type=\"a:Entity\">";
requestMain += " <a:Attributes>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>subject</c:key>";
requestMain += " <c:value i:type=\"d:string\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">";
requestMain += "已解决";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>incidentid</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>";
requestMain += CaseId;
requestMain += " </a:Id>";
requestMain += " <a:LogicalName>incident</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Attributes>";
requestMain += " <a:EntityState i:nil=\"true\" />";
requestMain += " <a:FormattedValues />";
requestMain += " <a:Id>00000000-0000-0000-0000-000000000000</a:Id>";
requestMain += " <a:LogicalName>incidentresolution</a:LogicalName>";
requestMain += " <a:RelatedEntities />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>Status</c:key>";
requestMain += " <c:value i:type=\"a:OptionSetValue\">";
requestMain += " <a:Value>5</a:Value>";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>CloseIncident</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", false);
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.send(requestMain);
var strResponse = req.responseText;
var reg = /\<faultstring[\s\S]*\<\/faultstring\>/im;
var faultmsg = reg.exec(strResponse);
if (faultmsg != null) {
reg = /\>[\s\S]*\<\//im;
faultmsg = reg.exec(faultmsg.toString());
if (faultmsg != null) {
Xrm.Utility.alertDialog("解决案例出现错误. " + faultmsg.toString().substring(1, faultmsg.toString().length - 2), function () { });
}
}
else {
if (FormOrList == "Form") {
if (IsDirty) {
Xrm.Page.data.entity.attributes.forEach(
function (attribute, index) {
if (attribute.getIsDirty()) {
attribute.setSubmitMode("never");
}
}
);
}
Xrm.Utility.openEntityForm("incident", CaseId);
}
else {
location.reload();
}
}
}





众所周知,Ribbon Workbench 发布解决方案非常慢,很容易导致SQL Server timeout,所以我这里用另外的方法来发布,我是我首次想到并分享给大家的,我觉得还不错。转到 Xml 这个Tabpage,点击刷新图标(切记要点击刷新,不然你的更改不会反应出来),然后将其中的XML内容复制下来,当然最好还是稍微检查下这个xml。

我这里复制出来的内容如下,我这里还包括了以前我自己客制化的东西,你的可能不一样,仅供参考:
<?xml version="1.0" encoding="utf-16"?>
<RibbonDiffXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CustomActions>
<CustomAction Id="new.Mscrm.Form.incident.Reactivate.CustomAction" Location="Mscrm.Form.incident.MainTab.Save.Controls._children" Sequence="47">
<CommandUIDefinition>
<Button Alt="$Resources:Ribbon.Form.incident.MainTab.Actions.Reactivate" Command="Mscrm.Form.incident.Reactivate" Id="Mscrm.Form.incident.Reactivate" Image32by32="/_imgs/ribbon/ReactivateCase_32.png" Image16by16="/_imgs/ribbon/ReactivateCase_16.png" LabelText="$Resources:Ribbon.Form.incident.MainTab.Actions.Reactivate" Sequence="47" TemplateAlias="o1" ToolTipTitle="$Resources:Mscrm_Form_incident_MainTab_Actions_Reactivate_ToolTipTitle" ToolTipDescription="$Resources:Mscrm_Form_incident_MainTab_Actions_Reactivate_ToolTipDescription" ModernImage="ReactivateCase" />
</CommandUIDefinition>
</CustomAction>
</CustomActions>
<Templates>
<RibbonTemplates Id="Mscrm.Templates" />
</Templates>
<CommandDefinitions>
<CommandDefinition Id="Mscrm.Form.incident.Reactivate">
<EnableRules>
<EnableRule Id="Mscrm.CanChangeIncidentForm" />
<EnableRule Id="new.incident.EnableRule1.ReactivateEnableRule" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.CanChangeIncidentForm" />
<DisplayRule Id="Mscrm.IncidentIsInactive" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="Mscrm.CommandBarActions.reactivate" Library="/_static/_common/scripts/CommandBarActions.js" />
</Actions>
</CommandDefinition>
<CommandDefinition Id="Mscrm.Form.incident.Resolve">
<EnableRules>
<EnableRule Id="Mscrm.CanChangeIncidentForm" />
<EnableRule Id="Mscrm.IncidentIsActive" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.CanChangeIncidentForm" />
<DisplayRule Id="Mscrm.IncidentIsActive" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="CloseCaseAsResolved" Library="$webresource:new_/common/js/RibbonScript.js">
<CrmParameter Value="FirstPrimaryItemId" />
<StringParameter Value="Form" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules />
<DisplayRules>
<DisplayRule Id="Mscrm.CanChangeIncidentForm">
<EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" EntityName="incident" />
<EntityPrivilegeRule PrivilegeType="AppendTo" PrivilegeDepth="Basic" EntityName="incident" />
<EntityPrivilegeRule PrivilegeType="Create" PrivilegeDepth="Basic" EntityName="activitypointer" />
<EntityPrivilegeRule PrivilegeType="Append" PrivilegeDepth="Basic" EntityName="activitypointer" />
</DisplayRule>
<DisplayRule Id="Mscrm.IncidentIsInactive">
<FormStateRule State="Disabled" />
</DisplayRule>
<DisplayRule Id="Mscrm.IncidentIsActive">
<FormStateRule State="Existing" />
</DisplayRule>
</DisplayRules>
<EnableRules>
<EnableRule Id="Mscrm.CanChangeIncidentForm">
<FormStateRule State="Create" InvertResult="true" />
<RecordPrivilegeRule PrivilegeType="Write" AppliesTo="PrimaryEntity" />
<RecordPrivilegeRule PrivilegeType="AppendTo" AppliesTo="PrimaryEntity" />
</EnableRule>
<EnableRule Id="new.incident.EnableRule1.ReactivateEnableRule">
<OrRule>
<Or>
<CustomRule FunctionName="CheckOwnerEqualsCurrentUser" Library="$webresource:new_/common/RibbonScript.js" />
</Or>
<Or>
<CustomRule FunctionName="CheckCurrentUserInTeam" Library="$webresource:new_/common/RibbonScript.js">
<StringParameter Value="MyTeam" />
</CustomRule>
</Or>
</OrRule>
</EnableRule>
<EnableRule Id="Mscrm.IncidentIsActive">
<FormStateRule State="Existing" />
</EnableRule>
</EnableRules>
</RuleDefinitions>
<LocLabels />
</RibbonDiffXml>
然后参考我的这篇博客:Dynamics CRM命令栏定制基础知识及手动编辑customization.xml实例 ,将之前的Ribbon解决方案作为非托管解决方案导出,然后将复制好的内容去掉<?xml version="1.0" encoding="utf-16"?> 这行,还去掉 RibbonDiffXml 的所有属性及其值,然后替换掉 customizations.xml 文件中的第一个 RibbonDiffXml 的值,然后将这个解决方案导入CRM,发布它就可以测试了。我这里录入一个简单的案例如下:



在Dynamis CRM中打造一键保存关闭刷新案例的功能的更多相关文章
- Dynamics CRM中的地址知多D?
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复169或者20151105可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! CRM中的地址以前不是很了解,定 ...
- 【matlab】将matlab中数据输出保存为txt或dat格式
将matlab中数据输出保存为txt或dat格式 总结网上各大论坛,主要有三种方法. 第一种方法:save(最简单基本的) 具体的命令是:用save *.txt -ascii x x为变量 *.txt ...
- Android菜鸟的成长笔记(14)—— Android中的状态保存探究(上)
原文:[置顶] Android菜鸟的成长笔记(14)—— Android中的状态保存探究(上) 我们在用手机的时候可能会发现,即使应用被放到后台再返回到前台数据依然保留(比如说我们正在玩游戏,突然电话 ...
- 如何:使用 Visual Studio 中的一键式发布来部署 Web 应用程序项目
原文: 如何:使用 Visual Studio 中的一键式发布来部署 Web 应用程序项目 本主题介绍如何在以下产品中使用 一键式发布 发布(部署)Web 应用程序项目: Visual Studio ...
- Dynamics CRM中一个查找字段引发的【血案】
摘要: 本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复267或者20180311可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyon ...
- 如何批量修改网页 更新网站 一键保存 windows查看和排序
批量打开需要修改的网页,一键保存:一个网站会由很多网页组成,当需要大量更新的时候,如果一个个进行打开修改,效率会很低,内容修改不多,且容易修改的时候,可以用editplus这种小编辑软件批量打开,批量 ...
- H+ 编辑tab页 保存后 刷新列表tab页 并关闭自已。tabA页调用tabB页的方法
//注:在contabs.js文件中 $(function () { }); 方法外 加入 //注: data-name="' + menuName + '" 这句是加入的自定义属 ...
- 在Dynamics CRM中使用Bootstrap
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- 在Dynamics CRM中自定义一个通用的查看编辑注释页面
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复162或者20151016可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 注释在CRM中的显示是比较特别, ...
随机推荐
- TypeScript `this` 入参
考察下面的示例代码: class MyClass { constructor(protected foo: string) {} @MyDecorator bar() { console.log(&q ...
- 如何在CAD图纸中进行线性标注
在CAD中,都会在图纸中进行CAD标注,一般都是有CAD标注样式.CAD标注文字等.那其中有一个就是CAD线性标注?可以标注图纸间的距离?那如何在CAD图纸中进行线性标注呢?具体要怎么来进行操作?本篇 ...
- 剑指offer 22:验证栈的压入、弹出序列
题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压 ...
- [Go] 使用protobuf进行序列化和反序列化
先定义消息类型 orders.proto syntax = "proto2"; package message; message Orders { required int32 o ...
- Codeforces Global Round 5
传送门 A. Balanced Rating Changes 签到,分正负搞一下就行. B. Balanced Tunnel 题意: 给出\(n\)辆车的进洞顺序和出洞顺序,问有多少量车实现了洞中超车 ...
- 201871010107-公海瑜《面向对象程序设计(java)》第一周学习总结
201871010107-公海瑜<面向对象程序设计(java)>第一周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ ...
- Codeforces Round #598 (Div. 3) E. Yet Another Division Into Teams dp
E. Yet Another Division Into Teams There are n students at your university. The programming skill of ...
- 使用canal增量同步mysql数据库信息到ElasticSearch
本文介绍如何使用canal增量同步mysql数据库信息到ElasticSearch.(注意:是增量!!!) 1.简介 1.1 canal介绍 Canal是一个基于MySQL二进制日志的高性能数据同步系 ...
- HTML连载52-网易注册界面之上部完成、中部初探
一.看一下注释即可,都是前面学到的知识,然后进行整合完成网页的制作,未完待续,这个网易界面跨度可大三天. <!DOCTYPE html> <html lang="en&qu ...
- php date获取前一天的时间
结果: 结论: 第二种方式只使用了一个函数,所以更快一些,速度大约是第一种的两倍