Search

Oppourtunity Count for MSCRM4

This is a javascript which calculates the number of opportunities and displays in the navigation.
// OPPOURTUNITY COUNT_______________________
var OPPOURTUNITY_COUNT_ACC = function () {
if (crmForm.FormType != 1) {
var objectidguid = crmForm.ObjectId;
try{        
var OpprNavTxt = document.getElementById('navOpps').getElementsByTagName('NOBR')[0].innerText;
}
catch(e){ return; }

var fxml = "<fetch mapping='logical'><entity name='account'><no-attrs/><filter type='and'><condition attribute='accountid' operator='eq' value='" + objectidguid + "'/></filter><link-entity name='opportunity' from='customerid' to='accountid'><attribute name='name'/></link-entity></entity></fetch>";

var soap7 = "";
soap7 += GenerateAuthenticationHeader();
soap7 += "";
soap7 += fxml;
soap7 += "";
var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
XmlHttp.open("POST", "/mscrmservices/2007/CrmService.asmx", false);
XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
XmlHttp.setRequestHeader("Content-Length", soap7.length);
XmlHttp.send(soap7);
var resultText = XmlHttp.responseXML.text;
var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
oXmlDoc.async = false;
oXmlDoc.loadXML(resultText);
var results = oXmlDoc.getElementsByTagName('result');
var no_of_opp = results.length;
document.getElementById('navOpps').getElementsByTagName('NOBR')[0].innerText = OpprNavTxt + " (" + no_of_opp + ")";
}
};