Microsoft Dynamics CRM 用 JavaScript 調用自定義 Action

這裏寫圖片描述

原文地址:https://community.dynamics.com/crm/b/crminogic/archive/2016/12/20/execute-action-with-entitycollection-parameter-using-web-api-in-dynamics-365

function CallCustomActionWithEntityCollectionParameter() {
    try {

        var reqName = "new_Approve";
        var clientUrl = Xrm.Page.context.getClientUrl();
        var parameters = {
           "Accounts"://EntityCollection parameter
             [
                  {
                      "@odata.type": "Microsoft.Dynamics.CRM.account",    //entity type
                      "accountid": "C4CA0B66-59B9-E611-8106-C4346BDC0E01",//Record's guid
                      "name": "Test",//name field of the account entity
                      "accountnumber": "123"                              //accountnumber field of the account entity
                  },
                  {
                      "@odata.type": "Microsoft.Dynamics.CRM.account",
                      "accountid": "CD67D78E-16BB-E611-8109-C4346BDC3C21",
                      "name": "Test2",
                      "accountnumber": "1234"
                  }
             ]
        };

        //Create request
        var req = new XMLHttpRequest();
        req.open("POST", clientUrl + "/api/data/v8.2/" + reqName, true);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");

        req.onreadystatechange = function () {

            if (this.readyState == 4 /* complete */) {
                req.onreadystatechange = null;

                if (this.status == 200 || this.status == 204) {
                    //success callback   
                    console.log("Success");
                } else {
                    //error callback      
                    console.log("Error");
                }
            }
        };
        req.send(JSON.stringify(parameters));

    } catch (e) {
        alert(e.message);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章