/I am exploring using the Customer Engagement API to add attachments to incidents created (images, pdfs, etc...) - does anyone know of any samples that show how this can be implemented?
Thanks!
Thanks Clofly - I will validate if this is working for me today!
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,900 Super User 2024 Season 2
Martin Dráb 229,297 Most Valuable Professional
nmaenpaa 101,156