如何将约会标记为“已完成"当“完成"时在 dynamics 365 中使用 JavaScript 单击按钮 [英] How to mark an appointment as "completed" when the "finished" button is clicked using JavaScript in dynamics 365
问题描述
我下面的代码不起作用,它更改为完成并快速更改回来.…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………...................................................
My code below does not work, it changes to completed and quickly changes back. .....................................................................................................................................................
function OnLoad() {
Xrm.Page.data.process.addOnProcessStatusChange(statusOnChange);
}
function statusOnChange() {
status = Xrm.Page.data.process.getStatus();
if (status == "finished") {
markAsComplete();
}
}
function markAsComplete(){
if (Xrm.Page.getAttribute("statecode") != null && Xrm.Page.getAttribute("statuscode") != null){
Xrm.Page.getAttribute("statecode").setValue(1); //Changing Status to Completed
Xrm.Page.getAttribute("statecode").setSubmitMode("always");
Xrm.Page.getAttribute("statuscode").setValue(3); //Changing Status Reason to Completed
Xrm.Page.getAttribute("statuscode").setSubmitMode("always");
}else{
alert("statecode field is not available on the form");
}
}
推荐答案
要从 JavaScript 更改记录的状态,您应该调用工作流或将 PATCH
请求发送到 Web API.
To change the state of a record from JavaScript, you should either call a workflow or send a PATCH
request to the Web API.
通过 Web API 进行的更新如下所示:
An update via the Web API would look as follows:
var appointmentId = Xrm.Page.data.entity.getId();
var entity = {};
entity.statuscode = 3;
entity.statecode = 1;
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/appointments(" + appointmentId + ")", 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));
这篇关于如何将约会标记为“已完成"当“完成"时在 dynamics 365 中使用 JavaScript 单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!