Table of Contents Consolidated Top Contributors .Description about scriptScriptConclusion
Now this is interesting, not only administrators but also every community member wants to know who the top contributor on the social application is. And SharePoint understands this requirement and gives the report for every individual community site on the home page.
But what if you want the top contributors amongst all communities? As members may have joined more than one community and contributing in all communities; in that case how we can find the top contributors? OOB feature is not there as per my knowledge to fulfill this requirement. So I have created a ECMA script which finds out top 5 contributors from each community and then consolidates them and gives the final result.
So how it works?
Below screenshot shows the output. This script also sums the number of threads posted and number of replies made my members. Reputation Score is used as criteria to get top contributors.
<
head
>
style
type
=
"text/css"
.auto-style1 {
width: 169px;
}
</
script
src
"/js/jquery-1.7.1.min.js"
></
"/js/jquery.dataTables.min.js"
"text/javascript"
var allSitesToShow;
var ArrayOfMembers = new Array();
var ArrayOfListItemCollection = new Array();
var context;
$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(GetAllCommunitySites, "sp.js");
});
function GetAllCommunitySites() {
debugger;
context = new SP.ClientContext.get_current();
this.Web = context.get_web();
allSitesToShow = this.Web.get_webs();
context.load(this.Web);
context.load(allSitesToShow);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessAllCommunitySites),
Function.createDelegate(this, this.onFailAllWebs));
function onSuccessAllCommunitySites(sender, args) {
var camlQuery = new SP.CamlQuery();
//var query = '<
View
/>';
var query = "<
><
Query
OrderBy
FieldRef
Name
'ReputationScore'
Ascending
'False'
RowLimit
>5</
>";
camlQuery.set_viewXml(query);
for (var i = 0 ; i <
allwebsToShow.get_count
() ; i++) {
if (allwebsToShow.get_item(i).get_webTemplate() == "COMMUNITY") {
//var
context
new
SP.ClientContext.get_current();
var
list
allwebsToShow
.get_item(i).get_lists().getByTitle("Community Members");
listItems_1
= list.getItems(camlQuery);
ArrayOfListItemCollection.push(listItems_1);
context.load(listItems_1);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessListItems), Function.createDelegate(this, this.onFailAllWebs));
function onSuccessListItems(sender, args) {
flag
false
;
for (var
i
0
; i < ArrayOfListItemCollection.length ; i++) {
j
; j < ArrayOfListItemCollection[i].get_count() ; j++) {
var Data ={
MemberName: ArrayOfListItemCollection[i].get_item(j).get_fieldValues().Title,
ReputationScore: ArrayOfListItemCollection[i].get_item(j).get_fieldValues().ReputationScore,
NumberOfDiscussions: ArrayOfListItemCollection[i].get_item(j).get_fieldValues().NumberOfDiscussions,
NumberOfReplies: ArrayOfListItemCollection[i].get_item(j).get_fieldValues().NumberOfReplies,
NumberOfBestResponses: ArrayOfListItemCollection[i].get_item(j).get_fieldValues().NumberOfBestResponses,
LookupId: ArrayOfListItemCollection[i].get_item(j).get_fieldValues().Member.get_lookupId()
k
; k < ArrayOfMembers.length ; k++) {
if (ArrayOfMembers[k].MemberName == Data.MemberName) {
true
break;
if (flag == true) {
ArrayOfMembers[k]
.ReputationScore
ArrayOfMembers
[k].ReputationScore + Data.ReputationScore;
.NumberOfDiscussions
[k].NumberOfDiscussions + Data.NumberOfDiscussions;
.NumberOfReplies
[k].NumberOfReplies + Data.NumberOfReplies;
else {
ArrayOfMembers.push(Data);
//alert(ArrayOfMembers);
= ArrayOfMembers.sort(function (a, b) { return b.ReputationScore - a.ReputationScore });
var htmlStart = "<table
'width:300px;'
>"
var htmlEnd = "</
table
var htmlstr = "";
ArrayOfMembers.length
; i++) { //ArrayOfMembers.length
if (i == 5)
htmlstr
= htmlstr + "<tr
'border-top:1pt solid black;'
td
'width:140px;vAlign:Top;'
a
href
'/_layouts/15/userdisp.aspx?ID=" + ArrayOfMembers[i].LookupId + "'
>" + ArrayOfMembers[i].MemberName + "</
'width:140px;'
tr
> Reputation Score: " + ArrayOfMembers[i].ReputationScore + "</
> Discussions posted: " + ArrayOfMembers[i].NumberOfDiscussions + "</
> Number Of Replies: " + ArrayOfMembers[i].NumberOfReplies + "</
$("#contribDiv").html(htmlStart + htmlstr + htmlEnd);
function onFailAllWebs(sender, args) {
alert('Failed:' + args.get_message());
div
id
"contribDiv"
"border:solid 1px #070303;"
SharePoint 2013: SharePoint Community Site as Real Time Social Communities or Groups.
Maheshkumar S Tiwari edited Original. Comment: Added tags