簡體   English   中英

當在Dynamics 365中使用JavaScript單擊“完成”按鈕時,如何將約會標記為“完成”

[英]How to mark an appointment as “completed” when the “finished” button is clicked using JavaScript in dynamics 365

我下面的代碼不起作用,它更改為已完成,然后迅速改回。 .................................................. .................................................. .................................................

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更改記錄的狀態,您應該調用工作流或向Web API發送PATCH請求。

通過Web API進行的更新如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM