Record count next to entity name in left side bar

This question is answered

I'm looking at CRM 2011 on premise and want to display the record count for each entity in the sidebar. 

For example in the Account form under Sales I'd like to see

Opportunities (20)

Quotes (5)

Orders (3)

I found this article

http://crmxpg.nl/wp/2010/09/22/show-number-of-related-activitieshistory-for-a-record-part-2/

but had problems getting the code to work (it was written for CRM 4.0).

 

This is a feature currently in Salesforce.

 

Thanks

Verified Answer
  • Here is something quick I came up with as an example. From an Account record it will show the number of open Opportunities in the left hand navigation. Basically what I did was create an oData query to find the result set I wanted the count on, and appended the count of the results to the corresponding menu item. You'll need jQuery as a Web Resource for this to work. Check out the CRM 2011 OData Query Designer on CodePlex for a useful tool to help build the oData queries. 

    function GetOpenOpportunityCount() {
        var guid = Xrm.Page.data.entity.getId();
        var urlSelect = "http://YOURSERVER/YOURORG/xrmservices/2011/OrganizationData.svc/OpportunitySet?$filter=AccountId/Id eq guid'"
            + guid + "' and StateCode/Value eq 0";
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: urlSelect,
            beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
            success: function (data, textStatus, XmlHttpRequest) {
                $("#navOpps").children(".ms-crm-Nav-Subarea-Title").append(" (" + data.d.results.length + ")");
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert('Error');
            }
        });
    }
    

     

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

All Replies
  • Here is something quick I came up with as an example. From an Account record it will show the number of open Opportunities in the left hand navigation. Basically what I did was create an oData query to find the result set I wanted the count on, and appended the count of the results to the corresponding menu item. You'll need jQuery as a Web Resource for this to work. Check out the CRM 2011 OData Query Designer on CodePlex for a useful tool to help build the oData queries. 

    function GetOpenOpportunityCount() {
        var guid = Xrm.Page.data.entity.getId();
        var urlSelect = "http://YOURSERVER/YOURORG/xrmservices/2011/OrganizationData.svc/OpportunitySet?$filter=AccountId/Id eq guid'"
            + guid + "' and StateCode/Value eq 0";
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: urlSelect,
            beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
            success: function (data, textStatus, XmlHttpRequest) {
                $("#navOpps").children(".ms-crm-Nav-Subarea-Title").append(" (" + data.d.results.length + ")");
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert('Error');
            }
        });
    }
    

     

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

  • Thanks, that worked.