function LookupValueOfAttributeInEntity(entityID, entityName, attributeName)
{
    // target

    var serverUrl = "/MSCrmServices/2007/CrmService.asmx";
    var
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open("POST", serverUrl, false);
    xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
    // message
   
var message =
    [
    "<?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>"
,
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"
,
    "<entityName>"
,
    entityName, // entity name (what we're looking in)
    "</entityName>",
    "<id>"
,
    entityID, // ID (of record we're looking for)
   
"</id>",
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"
,
    "<q1:Attributes><q1:Attribute>"
,
    attributeName, // attribute we want the value for
   
"</q1:Attribute></q1:Attributes>",
    "</columnSet></Retrieve>"
,
    "</soap:Body></soap:Envelope>"

    ].join("");
    xmlhttp.send(message);
    var
result = xmlhttp.responseXML.xml;
    var
doc = new ActiveXObject("MSXML2.DOMDocument");
    doc.async = false;
    doc.loadXML(result);
    var
tgtnode = doc.selectSingleNode("//q1:" + attributeName);
    if
(tgtnode != null)
    {
        return
tgtnode.text;
    }
    return
null;
}