Following code can be used to merge records using JavaScript and WebApi:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
var target = { leadid: "E5975EA3-531C-E511-80D8-3863BB3CE2C8"//Use contactid, accountid or incidentid to merge other entities }; target["@odata.type"] = "Microsoft.Dynamics.CRM.lead";//use contact, account or incident for other entities var subordinate = { leadid: "ED975EA3-531C-E511-80D8-3863BB3CE2C8"//Use contactid, accountid or incidentid to merge other entities }; subordinate["@odata.type"] = "Microsoft.Dynamics.CRM.lead";//use contact, account or incident for other entities var updatecontent = { leadid: "00000000-0000-0000-0000-000000000000"//Use contactid, accountid or incidentid to merge other entities }; updatecontent["@odata.type"] = "Microsoft.Dynamics.CRM.lead";//use contact, account or incident for other entities var parameters = {}; parameters.Target = target; parameters.Subordinate = subordinate; parameters.UpdateContent = updatecontent; parameters.PerformParentingChecks = true; var context; if (typeof GetGlobalContext === "function") { context = GetGlobalContext(); } else { context = Xrm.Page.context; } var req = new XMLHttpRequest(); req.open("POST", context.getClientUrl() + "/api/data/v8.2/Merge", 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) { //Success - No Return Data - Do Something } else { var errorText = this.responseText; //Error and errorText variable contains an error - do something with it } } }; req.send(JSON.stringify(parameters)); |
Is there an example of this using OData API for Java ?
I am constructing ClientEntity objects which get parsed to InputStream and sent to web api. This library attaches {fieldname@odata.type, fieldname:fieldvalue}
Not sure how to pass in this request using OData
Hello Vicky,
I’m afraid that I’m not an expert in Java to suggest.
Thanks,
Andrew
Can we merge custom entity records using this api
Hello Onkar,
Merge message supports only standard entities. For custom entities it would be required to create something own including client-side and server-side.
Andrew