Задача: нужно получить название организации (Business Unit) из Microsoft CRM. Решается следующим кодом
function UserHasBusinessUnit(businessUnits) { var mybu = GetMyBusinessUnit(); for (j = 0; j < businessUnits.length; j++) { if (mybu == businessUnits[j]) return true; } return false; } function GetMyBusinessUnit() { var xml = "" + "<?xml version='1.0' encoding='utf-8'?>" + "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" + " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" + GenerateAuthenticationHeader() + "<soap:Body>" + "<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + "<fetchXml>" + " <fetch mapping='logical' count='1'>" + " <entity name='businessunit'>" + " <attribute name='name' />" + " <filter>" + " <condition attribute='businessunitid' operator='eq-businessid' />" + " </filter>" + " </entity>" + " </fetch>" + "</fetchXml>" + "</Fetch>" + "</soap:Body>" + "</soap:Envelope>"; var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false); xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch"); xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlHttpRequest.setRequestHeader("Content-Length", xml.length); xmlHttpRequest.send(xml); var resultXml = xmlHttpRequest.responseXML; var resultSet = resultXml.text; resultSet.replace('<', '< '); resultSet.replace('>', '>'); var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM"); oXmlDoc.async = false; oXmlDoc.loadXML(resultSet); var result = oXmlDoc.getElementsByTagName('name'); return result[0].text; }