function getServiceUrl() { var serverUrl = Xrm.Page.context.getServerUrl(); if (serverUrl.match(/\/$/)) { serverUrl = serverUrl.substring(0, serverUrl.length - 1); } return serverUrl + "/XRMServices/2011/Organization.svc/web"; }
function Retrieve(entityName,entityId) { var request = "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>" request += "<s:Body>" request += "<Retrieve xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>" request += "<entityName>'"+ entityName +"'</entityName>" request += "<id>'"+ entityId +"'</id>" request += "<columnSet xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>" request += "<a:AllColumns>true</a:AllColumns>" request += "<a:Columns xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays' />" request += "</columnSet>" request += "</Retrieve>" request += "</s:Body>" request += "</s:Envelope>";
var xmlAjax = new XMLHttpRequest(); xmlAjax.open("POST", getServiceUrl(), true); xmlAjax.setRequestHeader("Accept", "application/xml, text/xml, */*"); xmlAjax.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlAjax.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Retrieve"); xmlAjax.onreadystatechange = function() { execresult(xmlAjax); }; xmlAjax.send(request); }
function execresult(ajax) { if (ajax.readyState == 4) { if (ajax.status == 200) { alert(ajax.responseXML); } } }