当先锋百科网

首页 1 2 3 4 5 6 7

这里写图片描述

原文地址: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 ==  /* complete */) {
                req.onreadystatechange = null;

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

    } catch (e) {
        alert(e.message);
    }
}