Update parent customerid in Contact using Soap Request

If you are looking to update parent customer id in contact record using soap request you can use below code. I have used Soaplogger application that comes with Microsoft CRM 2011 SDK to generate this soap request, you can simply write your server side code in soaploagger and run this application, it will generate client slide soap request for you.

function UpdateParentCustomer(ParentCustomerID,ContactID)
var _ServerURL = Xrm.Page.context.getServerUrl() + “/XRMServices/2011/Organization.svc/web”;
var SoapRequest=”<s:Envelope xmlns:s=’http://schemas.xmlsoap.org/soap/envelope/’>”+
“<s:Body><Update xmlns=’http://schemas.microsoft.com/xrm/2011/Contracts/Services&#8217; xmlns:i=’http://www.w3.org/2001/XMLSchema-instance’>”+
“<entity xmlns:a=’http://schemas.microsoft.com/xrm/2011/Contracts’>”+
“<a:Attributes xmlns:b=’http://schemas.datacontract.org/2004/07/System.Collections.Generic’>”+
“<b:value i:type=’a:EntityReference’>”+
“<a:Name i:nil=’true’ />”+
“<b:value i:type=’c:guid’ xmlns:c=’http://schemas.microsoft.com/2003/10/Serialization/’>”+ContactID+”</b:value>”+
“<a:EntityState i:nil=’true’ />”+
“<a:FormattedValues xmlns:b=’http://schemas.datacontract.org/2004/07/System.Collections.Generic&#8217; />”+
“<a:RelatedEntities xmlns:b=’http://schemas.datacontract.org/2004/07/System.Collections.Generic&#8217; />”+
var req = new XMLHttpRequest();
req.open(“POST”, _ServerURL, true)
req.setRequestHeader(“Accept”, “application/xml, text/xml, */*”);
req.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
req.setRequestHeader(“SOAPAction”, “http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Update&#8221;);
req.onreadystatechange = function () { Soap_Callback(req); };
function Soap_Callback(req)
if (req.readyState == 4) {
if (req.status == 200) {
alert(“Updated record successfully”);  }
else {var resultXml = req.responseXML;
var bodyNode = resultXml.firstChild.firstChild;
//Retrieve error message
for (var i = 0; i < bodyNode.childNodes.length; i++) {
var node = bodyNode.childNodes[i];
if (“s:Fault” == node.nodeName) {
for (var j = 0; j < node.childNodes.length; j++) {
var faultStringNode = node.childNodes[j];
if (“faultcode” == faultStringNode.nodeName) {
Hope it will help someone !!!



Leave a comment

Filed under MS CRM 2011

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s