if (typeof (SDK) == "undefined")
{ SDK = { __namespace: true }; }
//This will establish a more unique namespace for functions in this library. This will reduce the
// potential for functions to be overwritten due to a duplicate name when the library is loaded.
SDK.SAMPLES = {
_getServerUrl: function () {
var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
var serverUrl = "";
if (window.parent.Xrm.Page.data == null || window.parent.Xrm.Page.data == undefined) {
_serverUrl = Xrm.Page.context.getClientUrl();
}
else {
_serverUrl = window.parent.Xrm.Page.context.getClientUrl();
}
return serverUrl + OrgServicePath;
},
RetrieveVersionRequest: function () {
var requestMain = ""
requestMain += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";
requestMain += " <s:Body>";
requestMain += " <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";
requestMain += " <request i:type=\"b:RetrieveVersionRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\" xmlns:b=\"schemas.microsoft.com/.../Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\" />";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>RetrieveVersion</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", SDK.SAMPLES._getServerUrl(), true)
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");
var successCallback = null;
var errorCallback = null;
req.onreadystatechange = function () { SDK.SAMPLES.RetrieveVersionResponse(req, successCallback, errorCallback); };
req.send(requestMain);
},
RetrieveVersionResponse: function (req, successCallback, errorCallback) {
if (req.readyState == 4) {
if (req.status == 200) {
alert(req.responseXML.xml);
}
else {
errorCallback(SDK.SAMPLES._getError(req.responseXML));
}
}
},
_getError: function (faultXml) {
var errorMessage = "Unknown Error (Unable to parse the fault)";
if (typeof faultXml == "object") {
try {
var bodyNode = faultXml.firstChild.firstChild;
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 ("faultstring" == faultStringNode.nodeName) {
errorMessage = faultStringNode.text;
break;
}
}
break;
}
}
}
catch (e) { };
}
return new Error(errorMessage);
},
__namespace: true
};