Activities related to contacts in the account form

Jan 8, 2013 at 5:56 AM

First, I have to say thank you for this solution. It is (nearly -> see below) exactly the solution, I was looking for. It works great to show the number of contacts, but I have problems to show the number of activities. In the account form under "Activities" are all activities shown, that are related to the account AND to the contacts regarding to the account. The Navigation UI Record Counter counts only the records related directly to the account, not the activities related to the contacts of the account. It is the same problem as in the standard crm sub-grids on the form. Is there a way to count the number of activities related to the account and to the contacts?

My other problem is, that I can't count the number of closed activities. It's always the same number like the (open) activities.

Kind regards from Germany

Andreas

Jan 24, 2013 at 3:07 PM

I am also experiencing the Closed Activities showing the count of open activities.  My list of parameters is: ['navActivities:activitypointer:regardingobjectid','navActivityHistory:activitypointer:regardingobjectid']

Apr 8, 2013 at 6:31 PM
Has anyone figured out the "Closed Activity" showing the same amount as "Activities" I seem to be getting the same results.

thanks
Andy
Jun 25, 2013 at 5:42 PM
Edited Jun 25, 2013 at 5:46 PM
I am seeing this problem as well. If I have 1 open activity, I see (1) in both Activities and Closed Activities. Any reply from the author?
Jun 25, 2013 at 6:21 PM

I haven’t heard anything further on this. We turned it off from closed activities and have promoted up to the account date of last <activity type>.

Thanks,

Steve

Feb 3, 2015 at 11:51 AM
This is an old thread, but I've just started a CRM v2015 project and spent a little time figuring out the issue with closed activites.

You'll have to edit the source JS, and change the displayCount function to something like this. Notice the switch statement that works off the name of the navigation item. You can have activities count 'open' activites, and the other one count 'all' or 'closed' by modifying the statecode and statuscode part of the fetchxml.
    UIRecordCounter.Counter.displayCount = function (locations) {
        var $0 = Xrm.Page.data.entity.getId();
        if (locations != null && locations.length > 0) {
            for (var $1 = 0; $1 < locations.length; $1++) {
                var $2 = locations[$1];
                var $3 = $2.split(':');
                var $4 = $3[0];
                var $5 = $3[1];
                var $6 = $3[2];
                var _strFetchXML = "<fetch mapping='logical' distinct='false' aggregate='true'>";
                _strFetchXML += "<entity name='" + $5 + "'>";
                _strFetchXML += "<attribute name='" + $6 + "' alias='count' aggregate='count' />";
                _strFetchXML += "<filter type='and'>";
                switch($4)
                {
                    case "navActivities":
                        // This will count OPEN Activites only
                        _strFetchXML += "<condition attribute='statecode' operator='eq' value='0' />";
                        _strFetchXML += "<condition attribute='statuscode' operator='eq' value='2' />";
                        break;

                    case "navActivityHistory":
                        //// Count All Activities, leave this blank.
                        //// to count only CLOSED/Completed activities, add these to the string.
                        //_strFetchXML += "<condition attribute='statecode' operator='eq' value='1' />";
                        //_strFetchXML += "<condition attribute='statuscode' operator='eq' value='3' />";
                        break;

                    default:
                        _strFetchXML += "<condition attribute='statecode' operator='eq' value='0' />";
                        break;
                }
                _strFetchXML += "<condition attribute='" + $6 + "' operator='eq' value='" + $0 + "' />";
                _strFetchXML += "</filter></entity></fetch>";
                var $7 = UIRecordCounter.Counter.$1(_strFetchXML);
                UIRecordCounter.Counter.$0($4, $7);
            }
        }
Fair warning, no warranties expressed or implied, use this code at your own risk. :)
Feb 3, 2015 at 11:55 AM
Also, If you deploy this on CRM v2015, you have to change this function as well. Line 2 changes to .getClientUrl() to work properly.
UIRecordCounter.Counter.$2 = function () {
        var $0 = Xrm.Page.context.getClientUrl();
        var $1 = window.location.href.split('/');
        var $2 = $0.split('/');
        var $3 = '';
        for (var $4 = 0; $4 < $2.length; $4++) {
            if ($4 < 3) {
                $3 += $1[$4] + '/';
            } else {
                $3 += $2[$4] + '/';
            }
        } return $3;
    }