Articles about European Sharepoint Hosting Service
Posts tagged SharePoint 2013 Hosting poland
SharePoint 2013 Hosting – HostForLIFE.eu :: Custom Like And Comment Functionality For SharePoint Online Custom Pages
Sep 27th

You need to just add one content editor web part and add the below code into that web part. Below are the overall steps.Step 1
Create custom list in SharePoint having name “LikesList” to store all the likes given by the user. Add the below columns into it,
- column name : LikeBy type : Person or Group
- column name : CommentID type : Number
- column name : PageURL type : Single line of text
Create custom list in SharePoint having the name “CommentsList” to store all the comments added by user. Add the below columns into it,
- column name : ParentCommentID type : Number
- column name : CommentText type : Multiple lines of text
- column name : PageURL type : Single line of text
- column name : CommentBy type : Person or Group
Now create one text file and add the below code into it and save that file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
<div style="width: 70%;background-color: white;color: black; border-radius: 5px; padding:10px;"> <table style="width:100%"> <tbody> <tr> <td style="text-align: right;"> <span id="lblPageComments">0 Comments | </span> <span id="spLikes" title="" class="LikeClass"> <img id="imgLike" src="../_layouts/15/images/LikeFull.11x11x32.png?rev=23"> <span id="lblPageLikes">0</span> </span> <a id="lnkBtnPageLike" class="links">Like</a> <span id="LikeID" style="display:none;"></span> </td> </tr> <tr> <td style="padding-left: 5px;"> <h3>Comment : </h3> </td> </tr> <tr> <td style="padding: 25px;"> <textarea name="txtComments" rows="3" cols="20" id="txtComments" placeholder="Comment..." style="width:95%;"></textarea><br><br> <input type="button" name="btnPost" value="Post" id="btnPost"> <input type="button" name="btnReset" value="Reset" id="btnReset"> </td> </tr> </tbody> </table> <br> Comments... <table id="tblComments" style="width:100%"> </table> </div> <style type="text/css"> a { cursor: pointer; } </style> <script src="/JS/jquery.min.js"></script> <script src="/JS/jquery-ui.js"></script> <link rel="stylesheet" href="/CSS/jquery-ui.css"> <script src="JS/jquery-dateFormat.min.js"></script> <script type="text/javascript"> var PageURL = window.location.href; var UserID = _spPageContextInfo.userId; $(document).ready(function() { getSetPageDet(); getAllComments(); $("#btnPost").click(function() { AddComment(); }); $("#btnReset").click(function() { $("#txtComments").val(""); }); $("#lnkBtnPageLike").click(function() { if ($("#lnkBtnPageLike")[0].innerText == "Like") { LikePage(); } else { UnLikePage(); } }); }); // This function will reset the value of comment box function reset(textbox) { $("#txtReply_" + textbox).val(""); } // This function is used to get all the comments from comments list for that particular page having type as comment. function getAllComments() { $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items?$expand=CommentBy&$select=*,CommentBy/Title&$filter=PageURL eq '" + PageURL + "' and Title eq 'Comment'&$orderby=ID desc", type: "GET", headers: { "accept": "application/json;odata=verbose", "content-Type": "application/json;odata=verbose" }, success: function(data) { var commentsHTML = ""; if (data.d.results.length > 0) { $.each(data.d.results, function(index, value) { var CreatedDate = jQuery.format.date(value.Created, "ddd, MMM d, yyyy h:mm a"); commentsHTML += "<tr><td><span id='CommentsID_" + value.Id + "' style='display:none;'>" + value.Id + "</span><br><span>" + value.CommentText + "</span><br><a class='linksAuthor' href='/../../_layouts/15/userdisp.aspx?ID=" + value.CommentById + "' target='_blank'>" + value.CommentBy.Title + "</a><br><span>" + CreatedDate + "</spam> <span id='lblCommentReplies_" + value.Id + "'>0 Replies | </span><span id='spLikes_" + value.Id + "' title='' class='LikeClass'> <img src='../_layouts/15/images/LikeFull.11x11x32.png?rev=23'> <span id='lblLikes_" + value.Id + "' class='LikeClass'>0</span></span> <a id='lnkBtnLike_" + value.Id + "' class='links' onClick='LikeComment(" + value.Id + ")'>Like</a><span id='LikeID_" + value.Id + "' style='display:none;'></span>"; if (UserID == value.CommentById) { commentsHTML += " <a id='lnkBtnDelete_" + value.Id + "' class='links' onClick='DeleteComment(" + value.Id + ")'>Delete</a><br><br>Replies...<br><div style='margin-left: 10%;'><table style='width: 90%'><tbody><tr><td colspan='2'><textarea name='txtReply_" + value.Id + "' rows='1' cols='20' id='txtReply_" + value.Id + "' placeholder='Reply...' style='width:100%;'></textarea><br><br><input type='button' name='btnPostReply_" + value.Id + "' value='Post' id='btnPostReply_" + value.Id + "' onClick='AddReply(" + value.Id + ")'><input type='button' name='btnResetReply_" + value.Id + "' value='Reset' id='btnResetReply_" + value.Id + "' onClick='reset(" + value.Id + ")'></td></tr></tbody></table><div><table cellspacing='0' id='tblReply_" + value.Id + "' style='border-collapse:collapse;'></table></div></div><br><hr></td></tr>"; } else { commentsHTML += "<br><br>Replies...<br><div style='margin-left: 10%;'><table style='width: 90%'><tbody><tr><td colspan='2'><textarea name='txtReply_" + value.Id + "' rows='1' cols='20' id='txtReply_" + value.Id + "' placeholder='Reply...' style='width:100%;'></textarea><br><br><input type='button' name='btnPostReply_" + value.Id + "' value='Post' id='btnPostReply_" + value.Id + "' onClick='AddReply(" + value.Id + ")'><input type='button' name='btnResetReply_" + value.Id + "' value='Reset' id='btnResetReply_" + value.Id + "' onClick='reset(" + value.Id + ")'></td></tr></tbody></table><div><table cellspacing='0' id='tblReply_" + value.Id + "' style='border-collapse:collapse;'></table></div></div><br><hr></td></tr>"; } }); $("#tblComments")[0].innerHTML = commentsHTML; getSetCommentDet(); } }, error: function(error) { alert(JSON.stringify(error)); } }); } // This function is used to get all the likes from like list for that particular page. function LikeReply(CommentID) { var title = "Reply"; if ($("#lnkBtnReplyLike_" + CommentID)[0].innerText == "Like") { $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items", type: "POST", data: JSON.stringify({ '__metadata': { 'type': 'SP.Data.LikesListListItem' }, 'LikeById': UserID, 'Title': title, 'CommentID': CommentID }), headers: { "accept": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "content-Type": "application/json;odata=verbose" }, success: function(data) { $("#lnkBtnReplyLike_" + CommentID)[0].innerText = "Unlike"; }, error: function(error) { console.log(JSON.stringify(error)); } }); } else { $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items(" + $("#ReplyLikeID_" + CommentID)[0].innerText + ")", type: "POST", async: false, headers: { "Accept": "application/json;odata=verbose", "X-Http-Method": "DELETE", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "If-Match": "*" }, success: function(data) { $("#lnkBtnReplyLike_" + CommentID)[0].innerText = "Like"; getSetPageDet(); getAllComments(); }, error: function(data) { console.log(JSON.stringify(error)); } }); } } function LikeComment(CommentID) { var title = "Comment"; if ($("#lnkBtnLike_" + CommentID)[0].innerText == "Like") { $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items", type: "POST", data: JSON.stringify({ '__metadata': { 'type': 'SP.Data.LikesListListItem' }, 'LikeById': UserID, 'Title': title, 'CommentID': CommentID }), headers: { "accept": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "content-Type": "application/json;odata=verbose" }, success: function(data) { $("#lnkBtnLike_" + CommentID)[0].innerText = "Unlike"; }, error: function(error) { console.log(JSON.stringify(error)); } }); } else { $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items(" + $("#LikeID_" + CommentID)[0].innerText + ")", type: "POST", async: false, headers: { "Accept": "application/json;odata=verbose", "X-Http-Method": "DELETE", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "If-Match": "*" }, success: function(data) { $("#lnkBtnLike_" + CommentID)[0].innerText = "Like"; getSetPageDet(); getAllComments(); }, error: function(data) { console.log(JSON.stringify(error)); } }); } } function getSetCommentDet() { var commentIDColl = $('span[id^="CommentsID_"]'); $.each(commentIDColl, function(index, e) { var commentID = e.innerText; $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$filter=LikeById eq " + UserID + " and CommentID eq '" + commentID + "'", type: "GET", headers: { "accept": "application/json;odata=verbose", "content-Type": "application/json;odata=verbose" }, success: function(data) { if (data.d.results.length > 0) { $("#lnkBtnLike_" + commentID)[0].innerText = "Unlike"; $("#LikeID_" + commentID)[0].innerText = data.d.results[0].Id; } else { $("#lnkBtnLike_" + commentID)[0].innerText = "Like"; } }, error: function(error) { alert(JSON.stringify(error)); } }); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$expand=LikeBy&$select=*,LikeBy/Title&$filter=CommentID eq '" + commentID + "' and Title eq 'Comment'&$orderby=ID desc", type: "GET", headers: { "accept": "application/json;odata=verbose", "content-Type": "application/json;odata=verbose" }, success: function(data) { if (data.d.results.length > 0) { var likeToolTip = ""; var me = false; $("#lblLikes_" + commentID)[0].innerText = data.d.results.length; $.each(data.d.results, function(index, value) { if (value.LikeById == UserID) { me = true; } else { likeToolTip += value.LikeBy.Title + "; "; } }); if (me == true) { likeToolTip = "You; " + likeToolTip; } $("span#spLikes_" + commentID).attr("title", likeToolTip); } else { $("#lblLikes_" + commentID)[0].innerText = "0"; } }, error: function(error) { alert(JSON.stringify(error)); } }); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items?$expand=CommentBy&$select=*,CommentBy/Title&$filter=ParentCommentID eq '" + commentID + "' and Title eq 'Reply'&$orderby=ID desc", type: "GET", headers: { "accept": "application/json;odata=verbose", "content-Type": "application/json;odata=verbose" }, success: function(data) { if (data.d.results.length > 0) { $("#lblCommentReplies_" + commentID)[0].innerText = data.d.results.length + " Replies |"; var replyHTML = ""; if (data.d.results.length > 0) { $.each(data.d.results, function(index, value) { var CreatedDate = jQuery.format.date(value.Created, "ddd, MMM d, yyyy h:mm a"); replyHTML += "<tr><td><br><span id='ReplyID_" + value.Id + "' style='display:none;'>" + value.Id + "</span><br><span id='lblReply_" + value.Id + "' class='comments'>" + value.CommentText + "</span><br><a id='hrfReplyAuthor_" + value.Id + "' class='linksAuthor' href='/../../_layouts/15/userdisp.aspx?ID=" + value.CommentById + "' target='_blank'>" + value.CommentBy.Title + "</a><br><span id='lblReplydate_" + value.Id + "'>" + CreatedDate + "</span> <span id='spReplyLikes_" + value.Id + "' title='' class='LikeClass'> <img id='imgLike_" + value.Id + "' src='../_layouts/15/images/LikeFull.11x11x32.png?rev=23'> <span id='lblReplyLikes_" + value.Id + "' title='' class='LikeClass' ></span></span> <a id='lnkBtnReplyLike_" + value.Id + "' class='links' onClick='LikeReply(" + value.Id + ")'>Like</a><span id='ReplyLikeID_" + value.Id + "' style='display:none;'></span>"; if (UserID == value.CommentById) { replyHTML += " <a id='lnkBtnDelete_" + value.Id + "' class='links' onClick='DeleteReply(" + value.Id + ")'>Delete</a></td></tr>"; } else { replyHTML += "</td></tr>"; } }); $("#tblReply_" + commentID)[0].innerHTML = replyHTML; getSetReplyDet(); } } else { $("#lblCommentReplies_" + commentID)[0].innerText = "0 Replies |"; } }, error: function(error) { alert(JSON.stringify(error)); } }); }) } function getSetPageDet() { $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$filter=LikeById eq " + UserID + " and PageURL eq '" + PageURL + "'", type: "GET", headers: { "accept": "application/json;odata=verbose", "content-Type": "application/json;odata=verbose" }, success: function(data) { if (data.d.results.length > 0) { $("#lnkBtnPageLike")[0].innerText = "Unlike"; $("#LikeID")[0].innerText = data.d.results[0].Id; } else { $("#lnkBtnPageLike")[0].innerText = "Like"; } }, error: function(error) { alert(JSON.stringify(error)); } }); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$expand=LikeBy&$select=*,LikeBy/Title&$filter=PageURL eq '" + PageURL + "' and Title eq 'Page'", type: "GET", headers: { "accept": "application/json;odata=verbose", "content-Type": "application/json;odata=verbose" }, success: function(data) { if (data.d.results.length > 0) { var likeToolTip = ""; var me = false; $("#lblPageLikes")[0].innerText = data.d.results.length; $.each(data.d.results, function(index, value) { if (value.LikeById == UserID) { me = true; } else { likeToolTip += value.LikeBy.Title + "; "; } }); if (me == true) { likeToolTip = "You; " + likeToolTip; } $("span#spLikes").attr("title", likeToolTip); } else { $("#lblPageLikes")[0].innerText = "0"; } }, error: function(error) { alert(JSON.stringify(error)); } }); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items?$filter=PageURL eq '" + PageURL + "' and Title eq 'Comment'", type: "GET", headers: { "accept": "application/json;odata=verbose", "content-Type": "application/json;odata=verbose" }, success: function(data) { if (data.d.results.length > 0) { $("#lblPageComments")[0].innerText = data.d.results.length + " Comments |"; } else { $("#lblPageComments")[0].innerText = "0 Comments |"; } }, error: function(error) { alert(JSON.stringify(error)); } }); } function AddComment() { var title = "Comment"; var ParentCommentID = 0; var CommentText = $("#txtComments").val(); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items", type: "POST", data: JSON.stringify({ '__metadata': { 'type': 'SP.Data.CommentsListListItem' }, 'PageURL': PageURL, 'CommentById': UserID, 'Title': title, 'ParentCommentID': ParentCommentID, 'CommentText': CommentText }), headers: { "accept": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "content-Type": "application/json;odata=verbose" }, success: function(data) { $("#txtComments").val(""); getSetPageDet(); getAllComments(); }, error: function(error) { console.log(JSON.stringify(error)); } }); } function AddReply(CommentID) { var title = "Reply"; var CommentText = $("#txtReply_" + CommentID).val(); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items", type: "POST", data: JSON.stringify({ '__metadata': { 'type': 'SP.Data.CommentsListListItem' }, 'CommentById': UserID, 'Title': title, 'ParentCommentID': CommentID, 'CommentText': CommentText }), headers: { "accept": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "content-Type": "application/json;odata=verbose" }, success: function(data) { getSetPageDet(); getAllComments(); }, error: function(error) { console.log(JSON.stringify(error)); } }); } function LikePage() { var title = "Page"; var CommentID = 0; $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items", type: "POST", data: JSON.stringify({ '__metadata': { 'type': 'SP.Data.LikesListListItem' }, 'PageURL': PageURL, 'LikeById': UserID, 'Title': title, 'CommentID': CommentID }), headers: { "accept": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "content-Type": "application/json;odata=verbose" }, success: function(data) { $("#lnkBtnPageLike")[0].innerText = "Unlike"; getSetPageDet(); getAllComments(); }, error: function(error) { console.log(JSON.stringify(error)); } }); } function UnLikePage() { var title = "Page"; $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items(" + $("#LikeID")[0].innerText + ")", type: "POST", async: false, headers: { "Accept": "application/json;odata=verbose", "X-Http-Method": "DELETE", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "If-Match": "*" }, success: function(data) { $("#lnkBtnPageLike")[0].innerText = "Like"; }, error: function(data) { console.log(JSON.stringify(error)); getSetPageDet(); getAllComments(); } }); } function DeleteReply(CommentID) { $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items(" + CommentID + ")", type: "POST", async: false, headers: { "Accept": "application/json;odata=verbose", "X-Http-Method": "DELETE", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "If-Match": "*" }, success: function(data) { DeleteChildItems(CommentID); console.log("Comment deleted successfully!"); getSetPageDet(); getAllComments(); }, error: function(data) { console.log(JSON.stringify(error)); } }); } function DeleteComment(CommentID) { $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items(" + CommentID + ")", type: "POST", async: false, headers: { "Accept": "application/json;odata=verbose", "X-Http-Method": "DELETE", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "If-Match": "*" }, success: function(data) { DeleteChildItems(CommentID); console.log("Comment deleted successfully!"); getSetPageDet(); getAllComments(); }, error: function(data) { console.log(JSON.stringify(error)); } }); } function DeleteChildItems(parentId) { getItemsfromURL("/_api/web/lists/GetByTitle('LikesList')/items?$filter=CommentID eq " + parentId).done(function(data) { data.d.results.forEach(function(item) { var childId = item.ID; deleteItem("/_api/web/lists/GetByTitle('LikesList')/getItemById(" + childId + ")", item).done(function(d_data) { //deleted child item. }); }); }); getItemsfromURL("/_api/web/lists/GetByTitle('CommentsList')/items?$filter=ParentCommentID eq " + parentId).done(function(data) { data.d.results.forEach(function(item) { var childReplyId = item.ID; deleteItem("/_api/web/lists/GetByTitle('CommentsList')/getItemById(" + childReplyId + ")", item).done(function(d_data) { //deleted child item. }); getItemsfromURL("/_api/web/lists/GetByTitle('LikesList')/items?$filter=CommentID eq " + childReplyId).done(function(data) { data.d.results.forEach(function(item) { var childLikeId = item.ID; deleteItem("/_api/web/lists/GetByTitle('LikesList')/getItemById(" + childLikeId + ")", item).done(function(d_data) { //deleted child item. }); }); }); }); }); } //Get items function getItemsfromURL(url) { return $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + url, type: "GET", headers: { "accept": "application/json;odata=verbose", } }); } //Delete Item function deleteItem(url, oldItem) { return $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + url, type: "DELETE", headers: { "accept": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "If-Match": oldItem.__metadata.etag } }); } function getSetReplyDet() { var commentIDColl = $('span[id^="ReplyID_"]'); $.each(commentIDColl, function(index, e) { var commentID = e.innerText; $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$filter=LikeById eq " + UserID + " and CommentID eq '" + commentID + "'", type: "GET", headers: { "accept": "application/json;odata=verbose", "content-Type": "application/json;odata=verbose" }, success: function(data) { if (data.d.results.length > 0) { $("#lnkBtnReplyLike_" + commentID)[0].innerText = "Unlike"; $("#ReplyLikeID_" + commentID)[0].innerText = data.d.results[0].Id; } else { $("#lnkBtnReplyLike_" + commentID)[0].innerText = "Like"; } }, error: function(error) { alert(JSON.stringify(error)); } }); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$expand=LikeBy&$select=*,LikeBy/Title&$filter=CommentID eq '" + commentID + "' and Title eq 'Reply'", type: "GET", headers: { "accept": "application/json;odata=verbose", "content-Type": "application/json;odata=verbose" }, success: function(data) { if (data.d.results.length > 0) { var likeToolTip = ""; var me = false; $("#lblReplyLikes_" + commentID)[0].innerText = data.d.results.length; $.each(data.d.results, function(index, value) { if (value.LikeById == UserID) { me = true; } else { likeToolTip += value.LikeBy.Title + "; "; } }); if (me == true) { likeToolTip = "You; " + likeToolTip; } $("span#spReplyLikes_" + commentID).attr("title", likeToolTip); } else { $("#lblReplyLikes_" + commentID)[0].innerText = "0"; } }, error: function(error) { alert(JSON.stringify(error)); } }); }) } </script> |
Step 4
Create one web part page add your contents in to it. Add one more content editor web part -> edit web part -> give path of the txt file-> click on apply -> click on ok-> save the page -> publish it.
Step 5
After publishing the page you will see a comment box to add the comments and a like button to like the particular page.
Step 6
You can add the above code into any web part page using content editor and you will see the above functionality is working.
SharePoint 2013 Hosting – HostForLIFE.eu :: How to Create & Configure Machine Translation Service
Sep 20th
In this post, I’m going to tell you how to create and configure the machine translation service for SharePoint 2013. To create the multi-language feature of SharePoint 2013 using Machine Translation Service, you need to make the ‘Machine Translation Service’ up and running in your farm.

Create Machine Translation Service
Step 1
Open Central Administration, go to Application Management section, and choose Manage service applications.
Step 2
On the ribbon, choose New, and then choose Machine Translation Service.
Step 3
On the next page type a name for the service application and fill in the details as shown in the screens below.
Step 4
Select the check box near ‘Add this service application’s proxy to the farm’s default proxy list.’ and verify the database name, and click OK.
Configure Machine Translation Service
Step 1
Click on the ‘Machine Translation Service’ we just created, under the ‘Manage Service Applications’ in Central Administration.
Step 2
In the Machine Translation Service Screen, there is a section called ‘Enabled File Extensions’. It depicts the file extension for which the translation is enabled. Uncheck the checkbox for the file extension for which you want to disable translation.
Step 3
In the Item Size Limits section:
- Maximum file size for binary files in KB. Microsoft Word documents are binary files: 51200
- Maximum file size for text files in KB. Plain-text, HTML, and XLIFF documents are text files: 5120
- Maximum character count for Microsoft Word documents: 500000
In the Online Translation Connection:
Under Web proxy server, select the check box for ‘Use default internet settings’ to use the default proxy settings to connect Internet or specify the port in the ‘Use the proxy specified’
In Rest of the section fill the following details:
- Translation processes: 1
- Frequency with which to start translations (minutes): 15
- Number of translations to start (per translation process): 200
- Maximum translation attempts: 2
- Maximum number of synchronous translation requests (per server): 10
- Maximum number of items which can be queued within a 24-hour period: No Limit
- Maximum number of items which can be queued within a 24-hour period per site subscription: No Limit
- Expiration time for completed job history (days): 7 Days
- Recycle threshold: 100
- Disable Office 97-2003 Document scanning? No
Then, click on ‘OK’ Button.
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options.

SharePoint 2013 Hosting UK – HostForLIFE.eu :: Color Formatting Of A SharePoint Online List Using JSON
Sep 18th
Here, we are going to see how to perform conditional formatting using JSON in a SharePoint online list. Nowadays, many people are seeking for a code to format the SharePoint list to make it more attractive to the end users.
In this way, I just tried to format my list items with some color code and here is my code by which the background color will get changed based on the item values.
Here, I have created one list with one column called colors and I have entered some color name, so based on the color name, it will change the background color.
Here is the JSON code to change the background color and text color as well. You can just copy and paste it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
{ "elmType": "div", "txtContent": "@currentField", "style": { "color": "#fff", "padding-left": "14px", "background-color": { "operator": "?", "operands": [ { "operator": "==", "operands": [ "@currentField", "Green" ] }, "#2ECC71", { "operator": "?", "operands": [ { "operator": "==", "operands": [ "@currentField", "Red" ] }, "#E74C3C", { "operator": "?", "operands": [ { "operator": "==", "operands": [ "@currentField", "Yellow" ] }, "#F1C40F", { "operator": "?", "operands": [ { "operator": "==", "operands": [ "@currentField", "Purple" ] }, "#76448A", "" ] } ] } ] } ] } } } |
You can add the JSON code in that particular column in two ways,
- Navigate to list setting -> column -> then add JSON code
- You can click the title of column in list view itself then column setting and format this column and JSON code editor will open on the right of the screen
And the final view of the list would be like below.
SharePoint 2013 Hosting UK – HostForLIFE.eu :: Reading The SharePoint News Using Rest API In SPFx
Sep 6th

SharePoint Search
https://tenantName.sharepoint/com/sites/Intranet/_api/search/query?querytext=’IsDocument:True AND FileExtension:aspx AND PromotedState:2′
https://tenantName.sharepoint/com/search/_api/search/query?querytext=’IsDocument:True AND FileExtension:aspx AND PromotedState:2′
Code Snippet
As we search the entire tenant for the news, how do we differentiate the news of different sites?
To get the SiteTitle you need to select it using the selectProperties in the REST Url like below,
1 |
https://tenantName.sharepoint/com/search/_api/search/query?querytext='IsDocument:True AND FileExtension:aspx AND PromotedState:2' &selectproperties='Title,Author,PictureThumbnailURL,SiteTitle,SPWebUrl,OriginalPath,LastModifiedTime,ViewsLifeTime,ViewsRecent,LikesCount,PromotedState’ |
SharePoint 2013 Hosting UK – HostForLIFE.eu :: PowerShell to Get/Add/Remove Users of Local Administrator Group
Aug 23rd
This article outlines how to get, add and remove users of a local administrator group on SharePoint servers using a PowerShell script.
Local Administrators
The script does the following functionality.
- Gets the local administrators of the machine.
- Adds a user to the local administrator of the machine (the user must enter the user details into the AddUsers.csv file and place it under the folder where the PowerShell script exists).
- Removes a user from the local administrator of the machine (the user must enter the user details into the RemoveUsers.csv file and place it under the folder where the PowerShell script exists).
Get the local administrators of the machine
The following piece of code gets the users under the local administrator group of the machine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Function GetServerAdministrators([Microsoft.SharePoint.Administration.SPFarm]$farm) { write-host "" write-host "Preparing to collect SP server administrator details" -fore magenta $output = $scriptbase + "\" + "ServerAdminDetails.csv" "ServerName" + "," + "AdminMember" | Out-File -Encoding Default -FilePath $Output; foreach($server in $farm.Servers) { foreach($instance in $server.ServiceInstances) { if($instance.TypeName -eq $timerServiceInstanceName) { [string]$serverName = $server.Name write-host "Collecting administrator details for the server " $servername -fore yellow $admins = invoke-command {net localgroup administrators | where {$_ -AND $_ -notmatch "command completed successfully"} | select -skip 4} -computer $serverName foreach($admin in $admins) { write-host $admin " is member of administrator group in server " $serverName -fore cyan $serverName + "," + $admin | Out-File -Encoding Default -Append -FilePath $Output; } write-host "Administrator details for the server " $serverName " has been collected" -fore green } } } Write-host "Administrator details collected for all the SP servers in the farm" -fore green } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Function AddUserToServerAdminGroup([String]$AdminMember, [String]$ServerName) { $ans = read-host "Do you want to add user $AdminMember to server $ServerName (y/n)? " if($ans -eq 'y') { write-host "Adding user " $AdminMember " to administrator group on server " $ServerName -fore yellow $AdminMember1 = $AdminMember.split("\") $AdminMember2 = $AdminMember1[0] + "/" + $AdminMember1[1] $GroupObj = [ADSI]"WinNT://$ServerName/Administrators" $GroupObj.Add("WinNT://$AdminMember2") write-host $AdminMember " added to the local administrator group on the server " $ServerName -fore green } else { write-host "User choose not to add user " $AdminMember " to the server " $ServerName " administrator group" -fore cyan } } |
Remove users from local administrator of the machine
The following piece of code helps to remove the users from the local administrator group on the SharePoint servers.
Execution Procedure
- Download and copy the script folder to the SharePoint server.
- Launch the SharePoint management shell.
- Navigate to the script path and execute the script.
Enter the desired option.
SharePoint 2013 Hosting UK – HostForLIFE.eu :: Find Default Page And Approve It Using Powershell In SPO
Aug 21st

Here, we are finding those default pages across site and subsites and approving it along with the particular user who created or modified.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
#Passing inputs through CSV file # Pass Site URL and Library Name as Inputs. Param( [Parameter(Mandatory = $true)] [string] $Csv) # Pass your DLL 's Add - Type - Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add - Type - Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" Add - Type - Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Publishing.dll" Import - Module Microsoft.Online.SharePoint.PowerShell # Not required for on premise site - Start $userId = "xxxx@msdcloud.onmicrosoft.com" $pwd = Read - Host - Prompt "Enter password" - AsSecureString $creds = New - Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd) $root = Import - Csv $Csv foreach($record in $root) { $TargetSite = $record.SharePointUrl $LibraryName = $record.LibraryName $ctx = New - Object Microsoft.SharePoint.Client.ClientContext($TargetSite) # Not required for on premise site - Start $ctx.credentials = $creds # Iterating across subsites and finding default pages. $web = $ctx.Web $ctx.Load($web.Webs) $ctx.ExecuteQuery() if ($web.Webs.Count - gt 0) { foreach($AllWeb in $web.Webs) { try {# Get all files from the Library $List = $AllWeb.Lists.GetByTitle($LibraryName) $q = New - Object Microsoft.SharePoint.Client.CamlQuery $q.ViewXml = "<View Scope='RecursiveAll' />" $Items = $List.GetItems($q) $ctx.Load($Items) $ctx.ExecuteQuery() $FileName = "default.aspx" Foreach($Item in $Items) { $File = $Item["FileRef"].Substring($Item["FileRef"].LastIndexOf("/") + 1) if ($File - eq $FileName) { if ($Item["_ModerationStatus"] - eq "2" - and($Item["Editor"].LookupValue - eq("xxxUserName") - or $Item["Editor"].LookupValue - eq("xxxUserName"))) { $Item["_ModerationStatus"] = "0" $Item.Update() $ctx.ExecuteQuery() write - host "done" } } } } catch { $_ | Out - File errors.txt - Append } } } if ($web.Webs.Count - eq 0) { try { #Get all files from the Library $List = $AllWeb.Lists.GetByTitle($LibraryName) $q = New - Object Microsoft.SharePoint.Client.CamlQuery $q.ViewXml = "<View Scope='RecursiveAll' />" $Items = $List.GetItems($q) $ctx.Load($Items) $ctx.ExecuteQuery() $FileName = "default.aspx" Foreach($Item in $Items) { $File = $Item["FileRef"].Substring($Item["FileRef"].LastIndexOf("/") + 1) if ($File - eq $FileName) { if ($Item["_ModerationStatus"] - eq "2" - and($Item["Editor"].LookupValue - eq("xxxUserName") - or $Item["Editor"].LookupValue - eq("xxxUserName"))) { $Item["_ModerationStatus"] = "0" $Item.Update() $ctx.ExecuteQuery() write - host "done" } } } } catch { $_ | Out - File errors.txt - Append } } } |
Configurations can require moderation approval to publish a list item or allow automatic approval. A published list item MUST have a Moderation Status of 0. The following are all possible valid values for Moderation Status.