Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

java script issue on ms crm 2011 online version

$
0
0

Hi All,

I have requirement to auto fill a text field based on look up value selection in MS CRM 2011 Online. I am  using google chrome browser to access our online crm.

I used this below java script  but gives error popup  that "undefined" when page onload and  onchange events.The same javascript works fine in onpremise crm 2011 in IE:9.

function GetDetails()
 {
    var EntityName, EntityId;      
    var resultXml;

    var LookupFieldObject = Xrm.Page.data.entity.attributes.get('parentcustomerid');
  
    if (LookupFieldObject.getValue() != null) 
    {   
        EntityId = LookupFieldObject.getValue()[0].id;
        EntityName = LookupFieldObject.getValue()[0].entityType;
       alert(EntityId);
        alert(EntityName);
       
        resultXml = RetrieveEntityById(EntityName, EntityId, 'new_companystatuscbo');

        // In retrieved XML document check if it has accountnumber attribute
        if (resultXml != null && resultXml.selectSingleNode('//q1:new_companystatuscbo') != null) 
        {

            // If XML document has account number attribute then assign to local variable AccountNumber
            var comp = resultXml.selectSingleNode('//q1:new_companystatuscbo').nodeTypedValue;

            //Display Account Number Value in a Message Box
            alert("Company Status :" + comp);

            //If required then use the below code line to set value in field on form
            Xrm.Page.data.entity.attributes.get('cv_companystatus').setValue(comp);
        }  

    }
}

// Do not make any changes to this function
function RetrieveEntityById(prmEntityName, prmEntityId, prmEntityColumns) {

    var resultXml, errorCount, msg, xmlHttpRequest, arrayEntityColumns, xmlEntityColumns;

    arrayEntityColumns = prmEntityColumns.split(",");

    for (var i = 0; i < arrayEntityColumns.length; i++) {
        xmlEntityColumns += "<q1:Attribute>" + arrayEntityColumns[i] + "</q1:Attribute>";
    }

    var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

    //Prepare the SOAP message.
    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'>" +
    authenticationHeader +
    "<soap:Body>" +
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<entityName>" + prmEntityName + "</entityName>" +
    "<id>" + prmEntityId + "</id>" +
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
    "<q1:Attributes>" +
    xmlEntityColumns +
   "</q1:Attributes>" +
    "</columnSet>" +
    "</Retrieve></soap:Body></soap:Envelope>";

    //call function to create Soap Request to ms crm webservice
    xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    resultXml = xmlHttpRequest.responseXML;

    var errorCount = resultXml.selectNodes('//error').length;

    if (errorCount != 0) {
        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
        alert("Error Message : " + msg);
    }
    else {
        return resultXml;
    }
}

What is wrong in this code.

Any help will be  appreciated 


Krishn Prasad Shetty


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>