在Dynamics 365上,我们尝试使用客户端Web API关闭事件。
查看了文档(C#语言)后,我们了解到我们首先需要创建一个IncidentResolution活动,我们已经成功完成了该活动。 但是,我们不知道该如何完全关闭事件实体。
我假设我们需要更新记录的stateCode和statusCode。但是,如果这样做,ajax总是返回500错误。
其他更新正常。
我们这里缺少什么吗?
var entity = {};
entity.statecode = 1; // Resolved
entity.statuscode = 5; // Problem Solved
entity.title = "Title of my case";
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/incidents(Case's guid)", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//Success - No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
答案 0 :(得分:1)
您必须使用CloseIncident Action和POST
方法来执行此操作。这不是使用PATCH
方法的简单更新请求,基本上,大小写关闭将创建一个Incident Resolution
实体记录。
通常,我将使用CRM REST构建器来编写请求,即使在这种情况下该代码段也无法成功执行。完整的工作代码示例:
var incidentresolution = {
"subject": "Put Your Resolve Subject Here",
"incidentid@odata.bind": "/incidents(<GUID>)", //Replace <GUID> with Id of case you want to resolve
"timespent": 60, //This is billable time in minutes
"description": "Additional Description Here"
};
var parameters = {
"IncidentResolution": incidentresolution,
"Status": -1
};
var context;
if (typeof GetGlobalContext === "function") {
context = GetGlobalContext();
} else {
context = Xrm.Page.context;
}
var req = new XMLHttpRequest();
req.open("POST", context.getClientUrl() + "/api/data/v8.2/CloseIncident", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//Success - No Return Data - Do Something
} else {
var errorText = this.responseText;
//Error and errorText variable contains an error - do something with it
}
}
};
req.send(JSON.stringify(parameters));