MS Dynamics CRM 4.0 – Displaying the Number of Notes on the Notes Tab

The Microsoft CRM default form layout displays the Notes section on a separate tab. I often hear complaints from users that they don’t know if any notes have been added without first clicking that tab. Many people don’t realize that just as with any other section, you can move the Notes section to another tab, just as you would any other section. So one approach that many of our users have liked is to place the Notes section on the first tab as shown below.

This works, but I personally find it annoying as the the cursor will ‘jump’ down to the Notes section, sometimes scrolling past the info on top set of information, and you have less room to see multiple notes. Since I tend to keep the Notes section on its own separate tab, I wanted to find a way to let users know that data exists on that tab prior to clicking it. I created the following script to display the number of notes on the tab label as shown in the screen shot below.

The script I used is shown below and should be added to the entity’s form onLoad function. Since this approach is entirely script based, it should also work on CRM Online. The tab where the Notes section exists must be called Notes for the script to work.

var totalNotes = getTotalNotes(crmForm.ObjectId);
setNoteTabName(totalNotes);
function setNoteTabName(count) {
    /* update note tab */
    if (crmForm.FormType != 1) {
        var cells = document.getElementsByTagName(“A”);
        for (var i = 0; i 0) {
                        cells[i].innerText = “Notes (” + count + “)”;
                        document.all.crmTabBar.style.width = “auto”;
                }
                break;
            }
        }
    }
}
// Helper method to return the total notes associated with an object
function getTotalNotes(objectId) {
        // Define SOAP message
        var xml =
        [
        “”,
        “”,
        GenerateAuthenticationHeader(),
        “”,
        “”,
        “”,
        “annotation”,
        “createdon”,
        “falseAnd”,
        “objectidEqual”,
        “”,
        objectId,
        “”,
        “”,
        “”,
        “”,
        “”
        ].join(“”);
        var resultXml = executeSoapRequest(“RetrieveMultiple”, xml);
        return getMultipleNodeCount(resultXml, “q1:createdon”);
}
// Helper method to execute a SOAP request
function executeSoapRequest(action, xml) {
    var actionUrl = “http://schemas.microsoft.com/crm/2007/WebServices/”;
    actionUrl += action;
    var xmlHttpRequest = new ActiveXObject(“Msxml2.XMLHTTP”);
    xmlHttpRequest.Open(“POST”, “/mscrmservices/2007/CrmService.asmx”, false);
    xmlHttpRequest.setRequestHeader(“SOAPAction”, actionUrl);
    xmlHttpRequest.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
    xmlHttpRequest.setRequestHeader(“Content-Length”, xml.length);
    xmlHttpRequest.send(xml);
    var resultXml = xmlHttpRequest.responseXML;
    return resultXml;
}
// Helper method to return total # of nodes from XML
function getMultipleNodeCount(tree, el) {
    var e = null;
    e = tree.getElementsByTagName(el);
    return e.length;
}

Naturally, all of the caveats apply…this code is presented as is and may not upgrade with future releases of Microsoft CRM.
Finally, since we are discussing Notes, a hot fix exists if you see that your Notes area just displays the spinning icon as referenced in this KB article:
http://support.microsoft.com/kb/951174

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: