locked
Script nolonger works RRS feed

  • Question

  • We have just moved up from CRM 4 online  to CRM 2011 online. I'm having a problem with a jscript.

    When we put an Account Name in the field the scrip goes out and populates the address fields it worked in CRM 4 but no longer works. Any help would be appreciated.

    Here is the script

     

     function new_accountnameid_onchange()
    {
    getBusinessEntities = function(xml) {
        // Create an instance of an XMLHTTP object.
        var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        // Configure the XMLHttp object for the
        // Microsoft CRM Web services.
        xmlHttpRequest.Open(
          "POST",
          "/mscrmservices/2007/CrmService.asmx",
          false
          );
        xmlHttpRequest.setRequestHeader(
          "SOAPAction",
          "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple"
          );
        xmlHttpRequest.setRequestHeader(
          "Content-Type", "text/xml; charset=utf-8"
          );
        xmlHttpRequest.setRequestHeader(
          "Content-Length", xml.length
          );
        // Send the XMLHttp request.
        xmlHttpRequest.send(xml);
        // Capture the XMLHttp response in XML format.
        var resultXml = xmlHttpRequest.responseXML;
        // Create an XML document that you can parse.
        var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        oXmlDoc.async = false;
        // Load the document that has the results.
        oXmlDoc.loadXML(resultXml.xml);
        // Get only the BusinessEntity results.
        var businessEntities = oXmlDoc.getElementsByTagName('BusinessEntity');
        return businessEntities;
    }


    if (crmForm.all.new_accountnameid.DataValue != null) {
        // Prepare variables for a contact to retrieve.
        var accountid = crmForm.all.new_accountnameid.DataValue[0].id;
        var authenticationHeader = GenerateAuthenticationHeader();
        // 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>" +
    "<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'" +
    " xsi:type='q1:QueryExpression'>" +
    "<q1:EntityName>account</q1:EntityName>" +
    "<q1:ColumnSet xsi:type='q1:ColumnSet'>" +
    "<q1:Attributes>" +
    "<q1:Attribute>address1_line1</q1:Attribute>" +
    "<q1:Attribute>address1_line2</q1:Attribute>" +
    "<q1:Attribute>address1_line3</q1:Attribute>" +
    "<q1:Attribute>address1_city</q1:Attribute>" +
    "<q1:Attribute>address1_postalcode</q1:Attribute>" +
    "<q1:Attribute>address1_stateorprovince</q1:Attribute>" +
    "<q1:Attribute>address1_country</q1:Attribute>" +
    "</q1:Attributes>" +
    "</q1:ColumnSet>" +
    "<q1:Criteria>" +
    "<q1:FilterOperator>And</q1:FilterOperator>" +
    "<q1:Conditions>" +
    "<q1:Condition>" +
    "<q1:AttributeName>accountid</q1:AttributeName>" +
    "<q1:Operator>Like</q1:Operator>" +
    "<q1:Values>" +
    "<q1:Value xsi:type='xsd:string'>" + accountid + "</q1:Value>" +
    "</q1:Values>" +
    "</q1:Condition>" +
    "</q1:Conditions>" +
    "</q1:Criteria>" +
    "</query>" +
    "</RetrieveMultiple>" +
    "</soap:Body>" +
    "</soap:Envelope>";
        //get the business entities
        var businessEntities = getBusinessEntities(xml);
        var line1;
        var line2;
        var line3;
        var city;
        var postalcode;
        var stateorprovince;
        var country;
        if (businessEntities.length > 0) {
            line1 = (businessEntities[0].selectSingleNode('./q1:address1_line1') == null) ? null : businessEntities[0].selectSingleNode('./q1:address1_line1').text;
            line2 = (businessEntities[0].selectSingleNode('./q1:address1_line2') == null) ? null : businessEntities[0].selectSingleNode('./q1:address1_line2').text;
            line3 = (businessEntities[0].selectSingleNode('./q1:address1_line3') == null) ? null : businessEntities[0].selectSingleNode('./q1:address1_line3').text;
            city = (businessEntities[0].selectSingleNode('./q1:address1_city') == null) ? null : businessEntities[0].selectSingleNode('./q1:address1_city').text;
            postalcode = (businessEntities[0].selectSingleNode('./q1:address1_postalcode') == null) ? null : businessEntities[0].selectSingleNode('./q1:address1_postalcode').text;
            stateorprovince = (businessEntities[0].selectSingleNode('./q1:address1_stateorprovince') == null) ? null : businessEntities[0].selectSingleNode('./q1:address1_stateorprovince').text;
            country = (businessEntities[0].selectSingleNode('./q1:address1_country') == null) ? null : businessEntities[0].selectSingleNode('./q1:address1_country').text;
        }

        //Use all those variable values to assign to your fields like the following example
        crmForm.all.new_address.DataValue = line1;
        crmForm.all.new_address2.DataValue = line2;
        crmForm.all.new_city.DataValue = city;
        crmForm.all.new_province.DataValue = stateorprovince;
        crmForm.all.new_postalcode.DataValue = postalcode;

      //This is useed to force a save after a change has been made to the address
        crmForm.all.new_address.ForceSubmit = true;
        crmForm.all.new_address2.ForceSubmit = true;
        crmForm.all.new_city.ForceSubmit = true;
        crmForm.all.new_province.ForceSubmit = true;
        crmForm.all.new_postalcode.ForceSubmit = true;
    }

     

     

    Thanks

    Wednesday, April 6, 2011 7:59 PM

Answers