One of your client want to have activities counters in
record left navigation for activities and closed activities.
Code sample:
function ActivitiesRecordCounter() {
if (formType != CREATEFORM) {
//
Get opened record all activites
var fetchXml = "<fetch
distinct='false' mapping='logical' output-format='xml-platform'
version='1.0'>" +
"<entity
name='activitypointer'>" +
"<attribute
name='activitytypecode'/>" +
"<attribute
name='subject'/>" +
"<attribute
name='statecode'/>" +
"<filter
type='and'>" +
"<condition
attribute='regardingobjectid' value='" +
Xrm.Page.data.entity.getId() + "'
operator='eq'/>" +
"</filter></entity></fetch>";
var _Activities = XrmServiceToolkit.Soap.Fetch(fetchXml);
var c = 0;
var d = 0;
//
Count all activites
for (var i = 0; i < _Activities.length; i++) {
switch (_Activities[i].attributes.statecode.formattedValue) {
case "Open":
c++;
break;
case "Scheduled":
c++;
break;
case "Completed":
d++;
break;
case "Canceled":
d++;
}
}
null != Xrm.Page.ui.navigation.items.get("navActivities")
&& Xrm.Page.ui.navigation.items.get("navActivities").setLabel(Xrm.Page.ui.navigation.items.get("navActivities").getLabel()
+ '(' + c + ')');
null != Xrm.Page.ui.navigation.items.get("navActivityHistory") && Xrm.Page.ui.navigation.items.get("navActivityHistory").setLabel(Xrm.Page.ui.navigation.items.get("navActivityHistory").getLabel() + '(' + d + ')');
}
}
Attach the above function to Onload event Handler.
No comments:
Post a Comment