原文地址: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":
[
{
"@odata.type": "Microsoft.Dynamics.CRM.account",
"accountid": "C4CA0B66-59B9-E611-8106-C4346BDC0E01",
"name": "Test",
"accountnumber": "123"
},
{
"@odata.type": "Microsoft.Dynamics.CRM.account",
"accountid": "CD67D78E-16BB-E611-8109-C4346BDC3C21",
"name": "Test2",
"accountnumber": "1234"
}
]
};
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 == ) {
req.onreadystatechange = null;
if (this.status == || this.status == ) {
console.log("Success");
} else {
console.log("Error");
}
}
};
req.send(JSON.stringify(parameters));
} catch (e) {
alert(e.message);
}
}