Skip to main content

Notifications

Announcements

No record found.

How to Merge records using WebApi

a33ik Profile Picture a33ik 84,321 Most Valuable Professional

Following code can be used to merge records using JavaScript and WebApi:

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));

 

Запись How to Merge records using WebApi впервые появилась CRM Mentor.


This was originally posted here.

Comments

*This post is locked for comments