October 10, 2014

Lookup errors with Google Chrome 38

Google released a new version (38.0.2125.101) that breaks (again) Dynamics CRM. When users try to open a lookup they get the following error:

Currently there isn't a fix for this issue and it is not related to the previous showModalDialog issue.

UPDATE:
Google Chrome 38.0.2125.111 fixed the lookup error, please update it.

A managed solution (unsupported) that fix this issue is available:
Google Chrome 38 Lookup Fix

Offline installers of Google Chrome V37 (32 and 64 bit) are available:
Google Chrome 37.0.2062.124 32 bit (MD5: 6CF617A12FB9B7169B6C69D328F63389)
Google Chrome 37.0.2062.124 64 bit (MD5: 91644DE37A8EC506163FCBBCBD9AD0E4)

Microsoft Support KB Article regarding this issue: http://support2.microsoft.com/kb/3008160

Now I will explain what and how Google Chrome broke the lookup functionality:

When the user opens a lookup, CRM calls the web service AppWebServices/LookupService.asmx (message RetrieveInlineSearchResults) in order to fetch the preview records:

With Internet Explorer and Firefox the web service returns 200 (OK) but with Google Chrome it returns 500 (Internal Server Error). Which is the difference between the POST request made by Chrome and the other browsers?
The correct request body is the following:
<?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">
    <soap:Body>
        <RetrieveInlineSearchResults xmlns="http://schemas.microsoft.com/crm/2009/WebServices">
            <typesArray>
                <int>1</int>
                <int>2</int>
            </typesArray>
            <bindingColumns></bindingColumns>
            <additionalParameters>...</additionalParameters>
            <positions>
                <int>0</int>
            </positions>
            <resolveEmailAddress>false</resolveEmailAddress>
            <savedQueryTypeParameter></savedQueryTypeParameter>
            <defaultViewId></defaultViewId>
            <values>
                <string></string>
            </values>
            <sortResults>true</sortResults>
        </RetrieveInlineSearchResults>
    </soap:Body>
</soap:Envelope>
Chrome V38 doesn't add the piece
            <values>
                <string></string>
            </values>
causing the web service call to fail.
I debugged the CRM JavaScript and I found the connected piece of code (JsProvider.ashx):
!isNullOrEmptyString($v_D) && $v_0.SetParameter("values", $v_6);
$v_6 contains the text inside the lookup, after CRM will put this value inside an array called aParameters (script global.ashx) in order to build the SOAP request.
CRM doesn't use an object but an array to handle the values and check with a function called IsNull if the value is already inside the parameters:
function pushCommandParameter(oParameter) {
    // oParameter.Name is "values"
    if (!IsNull(aParameters[oParameter.Name])) // Google Chrome returns always true when oParameter.Name is "values" !!!
        aParameters[aParameters[oParameter.Name]] = oParameter;
    else {
        aParameters[oParameter.Name] = aParameters.length;
        aParameters.push(oParameter);
    }
}
Google Chrome returns something when you access the property "values" of an array. This can be easily tested:
var myArray = new Array();
alert(myArray['values']); // it returns function values() { [native code] }
alert(myArray['anotherparameter']); // it returns undefined
Due to this new behavior of the arrays the SOAP request is not created correctly (the missing <values><string></string></values> piece) and CRM returns 500 (Internal Server Error).

Which is the reason of this change? Google Chrome V38 introduced a partial support for ECMAScript 6, including the method Array.prototype.values() that causes this behavior and consequently the lookup errors inside Dynamics CRM.

A fix is not available (an update of Google Chrome or Dynamics CRM is the only solution) so if you still have Google Chrome V37 you can disable the auto-update (instructions here) or use another browser (Internet Explorer or Firefox).

8 comments:

  1. Thank you. I already spent like an hour of search but now I can stop it. :)

    ReplyDelete
  2. Blast from the past. Chrome 51 appears to do the same thing.

    ReplyDelete
    Replies
    1. I noticed also inside the forums that a similar problem happens with Chrome again, but in my instances I am not able to reproduce the issue, do you have the exact steps to trigger the error?

      Delete
  3. I am having Win 7 32 bit and Chrome version 51.0.2704.103 m. Same issue, if I go on any lookup field on any of MS CRM 2013 form, when I click on Magnifier icon it gives me generic error(same as screenshot on top in this blog.)

    ReplyDelete
  4. We did resolve it after updating UR3 for SP1

    ReplyDelete