none
CRM 3.0 - How to lookup an account record in Javascript

    Question

  •  

    Hi all,

     

    I am trying to look up a company record and see if it is a private individual upon creation of a contact record on the OnLoad function of a contact form.

    How do I access the parent company record after getting its GUID and how do I access the field for private individual?

    Are there any function in javscript that do this? Where is the documentation that I can read to find out?

     

    This is what I have so far:

     

    // parent company variable

    var parentcomp  ;

     

    var CRM_FORM_TYPE_CREATE = 1;

     

    if (crmForm.FormType == CRM_FORM_TYPE_CREATE)

    {

     

       // Get the GUID of the parent customer

        parentcomp = crmForm.all.parentcustomerid.DataValue[0].id;

    // Need to find the code to lookup the parent company and then read the 'is private individual' field  

       if (“parent company is private individual”)

      {

                * do action*

        }

     

    Thanks,

     

    Stanley

    Wednesday, February 18, 2009 6:21 AM

Answers

  •  
    //GetAttributeValueFromID v3  
    function GetAttributeValueFromID(sEntityName, sGUID, sAttributeName)  
    {  
            var sXml = "";  
            var oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");  
            var serverurl = window.location.protocol+"//"+window.location.host;  
            /*set up the SOAP message*/  
            sXml += "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";  
            sXml += "<soap:Envelope" + " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"";  
            sXml += " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";  
            sXml += " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";  
            sXml += "<soap:Body>";  
            sXml += "<entityName" + " xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sEntityName +   
     
    "</entityName>";  
            sXml += "<id" +" xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sGUID + "</id>";  
            sXml += "<columnSet" + " xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\""  
            sXml += " xmlns:q=\"http://schemas.microsoft.com/crm/2006/Query\""  
            sXml += " xsi:type=\"q:ColumnSet\"><q:Attributes><q:Attribute>" + sAttributeName +   
     
    "</q:Attribute></q:Attributes></columnSet>";  
            sXml += "</soap:Body>";  
            sXml += "</soap:Envelope>";  
            /* send the message to the CRM Web service*/  
            oXmlHttp.Open("POST", serverurl + "/MsCrmServices/2006/CrmService.asmx",false);  
            oXmlHttp.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/Retrieve");  
            oXmlHttp.setRequestHeader("Content-Type", "text/xml;charset=iso-8859-1");  
            oXmlHttp.setRequestHeader("Content-Length", sXml.length);  
            oXmlHttp.send(sXml);  
            /* retrieve response and find attribute value*/  
            var result = oXmlHttp.responseXML.selectSingleNode("//" + sAttributeName);  
            if (result == null)  
            {  
                    return "";  
            }  
            else  
                    return result.text;  
    }  
    var val=GetAttributeValueFromID("account", crmForm.all.parentaccountid.DataValue[0].id, "attributetofetch"); 
    Wednesday, February 18, 2009 10:15 AM