<
script
src
=
"/SiteAssets/js/jquery.js"
></
>
"/js/jquery.dataTables.min.js"
type
"text/javascript"
var siteTitle;
var siteTemplate; //template for Community.
var siteURL;
var sitePermission ;
var siteDescription;
var allwebs, allwebsToShow;
function CreateSite() {
siteTitle = $("#siteTitle").val();
siteTemplate = "COMMUNITY#0"; //template for Community.
siteURL = siteTitle.replace(" ","");
sitePermission = true;
siteDescription = $("#siteDesc").val();
var clientContext = new SP.ClientContext.get_current();
this.Web = clientContext.get_web(); //.get_current();
var webInfo = new SP.WebCreationInformation();
webInfo.set_webTemplate(siteTemplate);
webInfo.set_description(siteDescription);
webInfo.set_title(siteTitle);
webInfo.set_url(siteURL);
webInfo.set_language("1033");
webInfo.set_useSamePermissionsAsParentSite(sitePermission);
allwebs = this.Web.get_webs();
//allwebs.add(webInfo);
clientContext.load(this.Web);
clientContext.load(allwebs);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
Function.createDelegate(this, this.onFail));
}
function onSuccess(sender, args) {
alert("Community Created successfuly.");
$("#siteTitle").val("");
$("#siteDesc").val("");
function onFail(sender, args) {
alert('Failed:' + args.get_message());
$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(GetAllCommunities, "sp.js");
});
function GetAllCommunities() {
debugger;
this.Web = clientContext.get_web();
allwebsToShow = this.Web.get_webs();
clientContext.load(allwebsToShow);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSuccessAllWebs),
Function.createDelegate(this, this.onFailAllWebs));
function onSuccessAllWebs(sender, args) {
var htmlStart = "<
table
id
'communityTable'
style
'margin-left:10px;'
><
thead
tr
th
>Name</
>Description</
>Delete</
>"
var htmlEnd = "</
var htmlstr = "";
for (var i = 0 ; i <
allwebsToShow.get_count
() ; i++) {
if (allwebsToShow.get_item(i).get_webTemplate() == "COMMUNITY") {
htmlstr
= htmlstr + "<tr
'border-top:1pt solid black;'
td
a
href
'" + allwebsToShow.get_item(i).get_url() + "'
>" + allwebsToShow.get_item
(i).get_title() + "</
>" + allwebsToShow.get_item(i).get_description() + "</
> "+ "<
'javascript:alert('
Delete')'>Delete</
>" + "</
$("#allCommunities").html(htmlStart + htmlstr + htmlEnd);
$('#communityTable').dataTable();
function onFailAllWebs(sender, args) {
</
"text/css"
#btnCreate {
height: 38px;
width: 293px;
font-size: medium;
background-color: #808080;
text-align: center;
#siteTitle {
height: 31px;
width: 378px;
font-size: large;
.auto-style1 {
padding: 0px;
width: 498px;
.auto-style2 {
padding-top: 0px;
.auto-style3 {
height: 44px;
padding-top:30px;
#siteDesc {
font-size: small;
width: 375px;
height: 89px;
.auto-style6 {
width: 405px;
.auto-style7 {
height: 12px;
div
"border:solid 1px #070303;width: 586px;"
"width: 574px"
"border:1px solid #070303;padding-left:25px;margin-left:15px; width: 551px;"
class
"auto-style6"
h3
>All Communities</
"allCommunities"
"width:100%"
"auto-style7"
"border:1px solid #070303;padding-left:25px;margin-left:15px; width: 549px;"
>New Community.
"padding-left:25px;margin-left:15px; width: 517px;"
"auto-style1"
"padding-top:15px;"
>Enter Name of Community </
"auto-style2"
input
"text"
"siteTitle"
/>
>Description of Community </
textarea
"siteDesc"
"auto-style3"
"padding-left:30px;"
"button"
"btnCreate"
value
"Create Community"
onclick
"CreateSite();"
Everyone including administrator wants to see the top contributors of community. In some organization it is used as a parameter to recognize and reward a person. So how will you get top contributors? Yes, SharePoint 2013 already provides this OOB using member’s lists view. You can see top contributors for community and this is specific to that community only and it is calculated on the basis of Reputation Score/points earned by members.
Now what if you want to see consolidated top Contributors amongst all communities? As in your social application, there are number of communities and members have joined more than one community. And now you want to find out top contributor amongst all communities, now how you can achieve it?
So here I have write a script which gives you consolidated top contributors and displays on the screen with their Reputation score, Name, number of replies and number of post.
width: 169px;
"/jquery-1.7.1.min.js"
"/jquery.dataTables.min.js"
var allSitesToShow;
var ArrayOfMembers = new Array();
var ArrayOfListItemCollection = new Array();
var context;
ExecuteOrDelayUntilScriptLoaded(GetAllCommunitySites, "sp.js");
function GetAllCommunitySites() {
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 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);
//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;'
ArrayOfMembers.length
; i++) { //ArrayOfMembers.length
if (i == 5)
'width:140px;vAlign:Top;'
'/_layouts/15/userdisp.aspx?ID=" + ArrayOfMembers[i].LookupId + "'
>" + ArrayOfMembers[i].MemberName + "</
'width:140px;'
> Reputation Score: " + ArrayOfMembers[i].ReputationScore + "</
> Discussions posted: " + ArrayOfMembers[i].NumberOfDiscussions + "</
> Number Of Replies: " + ArrayOfMembers[i].NumberOfReplies + "</
$("#contribDiv").html(htmlStart + htmlstr + htmlEnd);
"contribDiv"
"border:solid 1px #070303;"
How this script works?
This script is written for the scenario where approach 2 is used(refer above example). So it first finds out all community sites. And then it collects all top 5 contributors from all community, while doing this it checks whether member has joined more than one community and sums the Reputation score of all community. In last step it sorts the member collection on the basis of reputation score and displays on the screen.