Tuesday, April 28, 2009

Retrieve entity and attributes via Javascript

This example used to get via Javascript information regarding entity + attributes


this.GetEntityAttrbiutes = function (entityName){
var xml = "" +
"" +
GenerateAuthenticationHeader() +
" " +
" "
+
" " +
" 00000000-0000-0000-0000-000000000000" +
" IncludeAttributes" +
" " + entityName+ "" +
" false" +
"
" +
"
" +
"
" +
"
" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/MetadataService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=windows-1255");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
return (resultXml);
}

Enjoy,
Rami Heleg