我们有一个自定义按钮来取消CRM中的任务。自定义按钮会触发取消任务的javascript。我们已根据blog by Guru Prasad创建了该脚本。
它曾经在CRM 2013中工作,但在我们升级到CRM 2016后,它已不再适用了。单击该按钮将不会执行任何操作 - 没有错误消息等。由于CRM 2016中的新Turbo表单功能,这不起作用。当我关闭Turbo表单以使用旧表单时,取消任务按钮工作正常。
以下是我的脚本 - 您知道是否存在阻止脚本使用CRM 2016 Turbo Form功能的任何内容?
PS:最初Guru Prasad博客中的代码仍在使用getServerUrl()
,但根据msdn link,它已被弃用并更改为getClientUrl()
,我们已更新了我们的脚本 - 但仍然不工作
function cancelTaskRecord(RECORD_ID) {
//set Task record to Cancel status, then force to close the page
Xrm.Page.data.save().then(changeRecordStatus(RECORD_ID, 2, 6), Xrm.Page.ui.close());
}
function changeRecordStatus(RECORD_ID, stateCode, statusCode)
{
// create the SetState request
var request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
request += "<s:Body>";
request += "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
request += "<request i:type=\"b:SetStateRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
request += "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
request += "<a:KeyValuePairOfstringanyType>";
request += "<c:key>EntityMoniker</c:key>";
request += "<c:value i:type=\"a:EntityReference\">";
request += "<a:Id>" + RECORD_ID + "</a:Id>";
request += "<a:LogicalName>task</a:LogicalName>";
request += "<a:Name i:nil=\"true\" />";
request += "</c:value>";
request += "</a:KeyValuePairOfstringanyType>";
request += "<a:KeyValuePairOfstringanyType>";
request += "<c:key>State</c:key>";
request += "<c:value i:type=\"a:OptionSetValue\">";
request += "<a:Value>" + stateCode + "</a:Value>";
request += "</c:value>";
request += "</a:KeyValuePairOfstringanyType>";
request += "<a:KeyValuePairOfstringanyType>";
request += "<c:key>Status</c:key>";
request += "<c:value i:type=\"a:OptionSetValue\">";
request += "<a:Value>" + statusCode + "</a:Value>";
request += "</c:value>";
request += "</a:KeyValuePairOfstringanyType>";
request += "</a:Parameters>";
request += "<a:RequestId i:nil=\"true\" />";
request += "<a:RequestName>SetState</a:RequestName>";
request += "</request>";
request += "</Execute>";
request += "</s:Body>";
request += "</s:Envelope>";
//send set state request
$.ajax({
type: "POST",
contentType: "text/xml; charset=utf-8",
datatype: "xml",
url: Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web",
data: request,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
XMLHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
},
success: function (data, textStatus, XmlHttpRequest) {
Xrm.Page.ui.close();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
答案 0 :(得分:1)
在您的评论中,您已经提到在这两种情况下都会触发代码。这意味着您的问题是使用实际的Jquery调用来执行SetState请求。你的下一步是双重的,你实际上是在两种情况下发送请求(Jquery是否正确加载),并且是发送相同的请求。如果您有警报,可以在代码中放置一个断点,并确保jquery在两种情况下都有效。您还可以安装fiddler并比较Turbo Forms和legacy中的请求,以查看请求是否相同。