Hi TWPW,
Here are code.
1.create a case with web API.
var entity = {};
entity.title = "Test Case From API";
entity["customerid_account@odata.bind"] = "/accounts(e1192f1a-628e-ea11-a811-000d3a35bad3)";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() "/api/data/v8.2/incidents", 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) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)] )\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
2. Create Notes Attachment using Web API.
Image attached you need to pass it as base64 string as document body.
var entity = {};
entity.subject = "test from api";
entity.filename = "testpicture.png";
entity["objectid_incident@odata.bind"] = "/incidents(23e6ee7c-5812-e911-a96b-000d3a3638df)";
entity.documentbody = "iVBORw0KGgo...";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() "/api/data/v9.1/annotations", 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) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)] )\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
I have test them and they run successfully.
Regards,
Clofly