Patch for JavaScript errors from the nav bar in CRM 2015 with Update 0.2

With the CRM 2015 on-premise update 0.2, Microsoft have introduced a bug with the navigation bar at the top of the page. The steps to reproduce it are:

  1. Hover over the top-level node, e.g. Sales, to bring up the second level navigation.
  2. Within the second level navigation, click on the downward pointing chevron next to an item, for example “Contacts”, to reveal the third level navigation showing the recently viewed items.
  3. Select one of the recent items.
  4. After the page has loaded, repeat from step 1.

As soon as you open the nav bar the second time a JavaScript error will occur, causing the whole navigation bar to become stuck on the page.

I have managed to identify the problem and have developed a simple patch for the JavaScript file in question.

Obviously this patch is unsupported as it involves modifying the core CRM JavaScript files, so I recommend making a backup of the file in question so you can restore it when Microsoft release a supported patch in future.

The file in question is \Program Files\Microsoft Dynamics CRM\CRMWeb\_static\_controls\NavBar\NavBar.js. The file is minified so you’ll want to un-minify it first.

The first patch is to the Mscrm.ActionListControl.prototype.selectNode function:

selectNode: function (node) {
    this.unselectNodes();
    Mscrm.NavigationNodesBasedControl.prototype.selectNode.call(this, node);
    // BEGIN PATCH
    var nodeId = node.Id.replace('{', '').replace('}', '');
    $P_CRM("#" + nodeId + ".nav-rowBody").addClass("selected");
    // END PATCH
    // $P_CRM("#" + node.Id + ".nav-rowBody").addClass("selected");
}

The second patch is to the Mscrm.ScrollableContentDescriptor.prototype.getScrollableElementIndex function:

getScrollableElementIndex: function (selectedElementId) {
    if (isNullOrEmptyString(selectedElementId)) return -1;
    // BEGIN PATCH
    selectedElementId = selectedElementId.replace('{', '').replace('}', '');
    // END PATCH
    for (var $v_0 = "#" + selectedElementId, $v_1 = $P_CRM(this.$1X_0), $v_2 = 0; $v_2 < $v_1.length; $v_2++)
        if ($P_CRM($v_0, $v_1[$v_2]).length > 0) return $v_2;
    return -1
},

Alternatively, you can download an already modified version of the file here: NavBar.js.

1 comment

Leave a Reply