我在我的 CRM 在线 V9 中创建了一个自定义操作,其中包含 2 个参数、一个对联系人的实体引用和一个字符串。
我检查了模式名称是否正确(大写和小写),甚至尝试使用 rest builder 生成代码,但我不断收到“错误请求”错误。
这是我的代码:
var parameters = {};
var contact = {};
contact.primarykeyid = "49A0E5B9-88DF-E311-B8E5-6C3BE5A8B200";//I added an hard coded value for testing
contact["@odata.type"] = "Microsoft.Dynamics.CRM.contact";
parameters.Contact = contact;
parameters.Text = "Some Text";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/new_CreateSMSrecord", false);
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 === 200) {
var results = JSON.parse(this.response);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(parameters));