gpt4 book ai didi

javascript - 无法通过 Web API 客户端关闭事件

转载 作者:行者123 更新时间:2023-11-30 20:23:06 26 4
gpt4 key购买 nike

在 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));

最佳答案

你必须使用 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));

Reference

关于javascript - 无法通过 Web API 客户端关闭事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51245785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com