Introduction

This is developed using the NAPA development tool. You can just pass the Document URL in the Text box. When the Validate button is clicked the Result will be displayed in an alert message.

Step 1

On your Developer Site, open the "Napa" Office 365 Development Tools and then choose Add New Project.


Step 2

Change the Permissions.

Tenant = Write

User Profiles = Read



Step 3

Update Default.aspx and App.js files.

Default ASPX



App.js

  1. 'use strict';
  2. var hostweburl;
  3. var appweburl;
  4. var followedDocumentURI;
  5. var documentUrl;
  6. // Get the SPAppWebUrl parameter from the query string and build
  7. // the Following manager endpoint.
  8. $(document).ready(function() {
  9. hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
  10. appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
  11. followedDocumentURI = decodeURIComponent(appweburl) + "/_api/social.following";
  12. $("#btnclick").click(function(event) {
  13. documentUrl = document.getElementById("isDocFollowed").value;
  14. isFollowed();
  15. event.preventDefault();
  16. });
  17. $.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js");
  18. });
  19. function isFollowed() {
  20. $.ajax({
  21. url: followedDocumentURI + "/isfollowed",
  22. type: "POST",
  23. data: JSON.stringify({
  24. "actor": {
  25. "__metadata": {
  26. "type": "SP.Social.SocialActorInfo"
  27. },
  28. "ActorType": 1,
  29. "ContentUri": documentUrl,
  30. "Id": null
  31. }
  32. }),
  33. headers: {
  34. "accept": "application/json;odata=verbose",
  35. "content-type": "application/json;odata=verbose",
  36. "X-RequestDigest": $("#__REQUESTDIGEST").val()
  37. },
  38. success: isFollowedSuccessHandler,
  39. error: isFollowedErrorHandler
  40. });
  41. }
  42. function isFollowedSuccessHandler(data) {
  43. var stringData = JSON.stringify(data);
  44. var jsonObject = JSON.parse(stringData);
  45. if (jsonObject.d.IsFollowed === true) {
  46. alert('The user is currently following the document.');
  47. } else {
  48. alert('The user is currently NOT following the document.');
  49. }
  50. }
  51. function isFollowedErrorHandler(data, errorCode, errorMessage) {
  52. alert(errorMessage);
  53. }
  54. function getQueryStringParameter(paramToRetrieve) {
  55. var params = document.URL.split("?")[1].split("&");
  56. for (var i = 0; i < params.length; i = i + 1) {
  57. var singleParam = params[i].split("=");
  58. if (singleParam[0] == paramToRetrieve) return singleParam[1];
  59. }
  60. }

Step 4

Publish the solution and click the Trust It Button.



Step 5

Enter the Document Library URL and click on the Validate Button.



Output