jun 24 Microsoft CRM

Show count of notes on a form in Microsoft CRM

Use the code below if you want to show the number of notes on a form:

The Code:

//START:Show count of notes
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 < cells.length; i++) {
            if (cells[i].innerText == “Notes”) // Remember to change the name if not are using english

{
                if (count > 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 =
        [
        “”,
        “
        “xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” “,
        “xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>”,
        GenerateAuthenticationHeader(),
        ““,
        ““,
        “
        “xsi:type=’q1:QueryExpression’>”,
        “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;
}
//END: Count of notes

Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+

2 comments on “Show count of notes on a form in Microsoft CRM

Skriv et svar

Din e-mailadresse vil ikke blive offentliggjort. Krævede felter er markeret med *